例題:請補充main函式,該函式的功能是:從字串 s中取出所有數字字符,并分別計數,把結果保存在陣列a中并輸出,把其它字符保存在a[10]中,
例如:當str1= “12312300abc8976542”時,結果為0:2 1:2 2:3 3:2 4:1 5:1 6:1 7:1 8:1 9:1 other character:3,
僅在橫線上填寫所需的若干運算式或陳述句,請勿改動函式中的其它任何內容,
代碼如下:
#include<stdio.h>
#include<conio.h>
main()
{
int j,a[11];
char*s="12312300abc8976542";
char*t=s;
printf("The origial data is:\n");
puts(s);
for(j=0;j<11;j++)
a[j]=0;
while(*t)
{
switch(*t)
{
case '0':a[0]++;break;
case '1':a[1]++;break;
case '2':a[2]++;break;
case '3':a[3]++;break;
case '4':a[4]++;break;
case '5':a[5]++;break;
case '6':a[6]++;break;
case '7':a[7]++;break;
case '8':a[8]++;break;
case '9':a[9]++;break;
default:a[10]++;
}
t++;
}
printf("The result \n");
for(j=0;j<10;j++)
printf("\n%d:%d",j,a[j]);
printf("\nnother character:%d\n",a[j]);
}
輸出運行視窗如下:

越努力越幸運!
加油,奧力給!!!
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/250256.html
標籤:其他
上一篇:Typora初步學習
