int main(void) { int Score[10]={0},ScoreInt=0,i; char ScoreString[200]; char *ptr=ScoreString;
gets(ScoreString);
while(*ptr) {
if(*ptr>='0'&&*ptr<='9') { Score[ScoreInt]*=10; Score[ScoreInt]+=*ptr-'0'; } else if(*ptr==',') { ScoreInt++; } else { printf("输入错误!\n"); sleep(3); exit(0); } ptr++; }
for(i=0;i<10;i++) { printf("%5d",Score[i]); } } 请注意发贴规则,初级问题请发到相应版块。
楼主,难道你认为你这个问题也属于高手的范围吗?没仔细看过书吧? #include <stdio.h>
main() { int Score[10],i; printf("Please input the number\n"); scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",&Score[0],&Score[1],&Score[2],&Score[3],&Score[4],&Score[5],&Score[6],&Score[7],&Score[8],&Score[9]); for(i=0;i<=9;i++) { printf("%d,",Score[i]); } getch(); }
int main(void) { int Score[10]={0},ScoreInt=0,i; char ScoreString[200]; char *ptr=ScoreString;
gets(ScoreString);
while(*ptr) {
if(*ptr>='0'&&*ptr<='9') { Score[ScoreInt]*=10; Score[ScoreInt]+=*ptr-'0'; } else if(*ptr==',') { ScoreInt++; } else { printf("输入错误!\n"); sleep(3); exit(0); } ptr++; }
for(i=0;i<10;i++) { printf("%5d",Score[i]); } } 请注意发贴规则,初级问题请发到相应版块。
謝謝版主朋友的回答,但..這段代碼看不明白阿...
楼主,难道你认为你这个问题也属于高手的范围吗?没仔细看过书吧? #include <stdio.h>
main() { int Score[10],i; printf("Please input the number\n"); scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",&Score[0],&Score[1],&Score[2],&Score[3],&Score[4],&Score[5],&Score[6],&Score[7],&Score[8],&Score[9]); for(i=0;i<=9;i++) { printf("%d,",Score[i]); } getch(); }
想問一下這版主大人,為什麽要加 getch() 呢.? 有什麽作用?不加也可以的吧.
int main(void) { int Score[10]={0},ScoreInt=0,i; char ScoreString[200]; char *ptr=ScoreString;
gets(ScoreString);
while(*ptr) {
if(*ptr>='0'&&*ptr<='9') { Score[ScoreInt]*=10; Score[ScoreInt]+=*ptr-'0'; } else if(*ptr==',') { ScoreInt++; } else { printf("输入错误!\n"); sleep(3); exit(0); } ptr++; }
for(i=0;i<10;i++) { printf("%5d",Score[i]); } } 请注意发贴规则,初级问题请发到相应版块。
没必要写这么复杂吧