1 int is_integer(char ptr[]) 2 { 3 int len = strlen(ptr); 4 int ret = 0; 5 int i = 0; 6 for (i = 0; i < len; i++) 7 { 8 if (ptr[i] >= '0' && ptr[i] <= '9') 9 { 10 ret = ret * 10 + (ptr[i] - '0');//单个字符转化为数 11 } 12 else 13 { 14 return -1; 15 } 16 } 17 if (ret < 1 || ret>1000)//可以用来判断该数是否在要求范围内 18 { 19 return -1; 20 } 21 else 22 { 23 return ret; 24 } 25 }
标签:10,正整数,int,ret,len,return,2023.8,ptr From: https://www.cnblogs.com/muzhaodi/p/17621395.html