关键词:
#define _STDC_WANT_LIB_EXT1_ 1 #include <stdio.h> #include <string.h> #include <ctype.h> #include <stdlib.h> #include <stdbool.h> #include <math.h> #define BUF_LEN 256 int main(void) { char buf[BUF_LEN]; //char number_string[30]; char op = 0; //操作符 size_t index = 0; size_t to =0; size_t buf_length = 0; //unsigned int number_length = 0; double result = 0.0; double number =0.0; char *endptr = NULL; printf("To use this calculator, enter any expression with" " or without spaces."); printf(" An expression may include the operators"); printf(" +, -, *, /, %%, or ^(raise to a power)."); printf(" Use = at the beginning of a line to operate on "); printf(" the result of the previous calculation."); printf(" Enter quit to stop the calculator. "); //1.读入用户输入的字符串,是quit,就退出 char *ptr =NULL; while(true) { ptr = fgets(buf,BUF_LEN,stdin); if(ptr == false)//测试 { printf("Error reading input. "); return 1; } if(strcmp(buf,"quit ")==0) break; buf_length = strnlen_s(buf,BUF_LEN); buf[--buf_length] = ‘