先读1个整型数。
然后循环:读1个字符,如果字符是逗号则读1个整型数,如果不是逗号,循环就结束。
如果读整型数有错,循环也结束。
#include<stdio.h>
#include<stdlib.h>
main(){ int x[100],n=0,i;
int c;
if ( scanf("%d",&x[n])==1) n++;
while(1){
scanf("%c",&c);
if (c != ',') break;
if ( scanf("%d",&x[n])==1) n++;else break;
}
printf("\nI read: ");
for (i=0;i<n;i++) printf("%d ",x[i]);
return 0;
}
温馨提示:内容为网友见解,仅供参考