下面是作业题,请问怎么做呀?:
#include <stdio.h>
#define M 81
int fun(char *ss, char c)
{int i=0;
for(;*ss!='\0';ss++)
if(*ss==c)i++;
return i;
}
main()
{ char a[M], ch;
printf("\nPlease enter a string:"); gets(a);
printf("\nPlease enter a char:"); ch = getchar();
printf("\nThe number of the char is: %d\n", fun(a, ch));
NONO();
}
NONO()
{/* 本函数用于数据读入和结果写入文件, 考生无需修改 */
int i ;
FILE *rf, *wf ;
char a[M], b[M], ch ;
rf = fopen("C:\\WEXAM\\24010001\\in.dat", "r") ;
if(rf == NULL) {
printf("在考生文件夹下数据文件in.dat不存在!") ;
return ;
}
wf = fopen("C:\\WEXAM\\24010001\\out.dat", "w") ;
for(i = 0 ; i < 10 ; i++) {
fscanf(rf, "%s", a) ;
fscanf(rf, "%s", b) ;
ch = *b ;
fprintf(wf, "%c=%d\n", ch, fun(a, ch)) ;
}
fclose(rf) ;
fclose(wf) ;
} |