I was trying to parse a string and check if the string is in a correct order and only contains numbers. Example: "1,2,3,4:5:6"
我试图解析一个字符串,检查字符串是否正确,只包含数字。示例:“1,2,3,4:5:6”
I want to be able to separate the string and store each value separately. Only Standard C please.
我希望能够分离字符串并分别存储每个值。只有标准C请。
1 个解决方案
#1
-2
You can do this:
你可以这样做:
int a[1000], k=0, f = 0;for(int i=0; s[i]; i++) { if(s[i]>='0' && s[i]<='9' && f == 0) { a[k++] = atoi(s+i); f = 1; } else f = 0;}
** (Try to improve the code if you can)
**(如果可以的话,尝试改进代码)
#1
-2
You can do this:
你可以这样做:
int a[1000], k=0, f = 0;for(int i=0; s[i]; i++) { if(s[i]>='0' && s[i]<='9' && f == 0) { a[k++] = atoi(s+i); f = 1; } else f = 0;}
** (Try to improve the code if you can)
**(如果可以的话,尝试改进代码)