user-0 提问: 提问！！！恳请大家帮我看看这个题目

回复:
user: user-1
content: 没看到哪段代码统计了字符数啊？

user: user-0
content: 引用 2 楼 自信男孩 的回复:#include<stdio.h> #include<string.h> #include <ctype.h>  int alpha_cnt, digit_cnt, space_cnt, other_cnt, total_cnt; void merge_sort(char *a, char *b, char *c);  void sort(char x[]) {     int len, i, j;     char temp;     len = strlen(x);     for(i=0;i<len-1;i++)         for(j=0;j<len-i-1;j++)             if (x[j]>x[j+1])             {                 temp = x[j]; x[j] = x[j + 1]; x[j + 1] = temp;             } }   int main() {     FILE *fp;     char a[21], b[21], c[41];     /*     int lena, lenb;     int sum=1;     int ch;     int number = 0;     int character = 0;     int space = 0;     int total = 0;     char *pa, *pb, *pc;     */     if((fp=fopen("A2.txt","r"))==NULL)     {         printf("can't open file A2\n");         return 1;     }     while(fgets(a,21,fp)!=NULL)     {         printf("the content of file A2:");         printf("%s\n", a);     }     fclose(fp);     if((fp=fopen("B2.txt","r"))==NULL)     {         printf("can't open file B2\n");         return 1;     }     while(fgets(b,21,fp)!=NULL)     {         printf("the content of file B2:");         printf("%s\n", b);     }     sort(a);     sort(b);      /*     lena = strlen(a);     lenb = strlen(b);     pa = a; pb = b; pc = c;     while (pa <= a + lena - 1 && pb <= b + lenb - 1)     {         if (*pa <= *pb)             *pc++ = *pa++;         else *pc++ = *pb++;         sum++;     }      while (pa <= a + lena - 1) {         *pc++ = *pa++;         sum++;     }      while (pb <= b + lenb - 1) {         *pc++ = *pb++;         sum++;     }     */     merge_sort(a, b, c);     printf("digit: %d, alpha: %d, other: %d\n", digit_cnt, alpha_cnt, other_cnt);     return 0; }  void merge_sort(char *a, char *b, char *c) {     int lena, lenb;     char *pa, *pb, *pc;      lena = strlen(a);     lenb = strlen(b);     pa = a; pb = b; pc = c;     while (pa <= a + lena - 1 && pb <= b + lenb - 1)     {         if (*pa <= *pb)             //*pc++ = *pa++;             *pc = *pa++;         else             //*pc++ = *pb++;             *pc = *pb++;         if (isdigit(*pc))             digit_cnt++;         else if (isalpha(*pc))             alpha_cnt++;         else if (isspace(*pc))             space_cnt++;         else             other_cnt++;         total_cnt++;         pc++;     }      while (pa <= a + lena - 1) {         *pc = *pa++;         if (isdigit(*pc))             digit_cnt++;         else if (isalpha(*pc))             alpha_cnt++;         else if (isspace(*pc))             space_cnt++;         else             other_cnt++;         total_cnt++;         pc++;     }      while (pb <= b + lenb - 1) {         *pc = *pb++;         if (isdigit(*pc))             digit_cnt++;         else if (isalpha(*pc))             alpha_cnt++;         else if (isspace(*pc))             space_cnt++;         else             other_cnt++;         total_cnt++;         pc++;     }  } 供参考～  注意一下fgets会将'\n'放到缓存里。你好！感谢你的回答，我把完整的代码贴出来了，可不可以请你帮我在源代码的基础上修改呀，感谢~

user: user-0
content: 不好意思，代码没有复制完全，完整的在下面 #include<stdio.h> #include<string.h> void sort(char x[]) { int len, i, j; char temp; len = strlen(x); for(i=0;i<len-1;i++) for(j=0;j<len-i-1;j++) if (x[j]>x[j+1]) { temp = x[j]; x[j] = x[j + 1]; x[j + 1] = temp; } } int main() { FILE *fp; char a[21], b[21], c[41]; int lena, lenb; int sum=1; int ch; int number = 0;         int character = 0;         int space = 0;         int total = 0; char *pa, *pb, *pc; if((fp=fopen("A2.txt","r"))==NULL) { printf("can't open file A2\n"); return 1; } while(fgets(a,21,fp)!=NULL) { printf("the content of file A:"); printf("%s\n", a); } fclose(fp); if((fp=fopen("B2.txt","r"))==NULL) { printf("can't open file B2\n"); return 1; } while(fgets(b,21,fp)!=NULL) { printf("the content of file B2:"); printf("%s\n", b); } sort(a); sort(b); lena = strlen(a); lenb = strlen(b); pa = a; pb = b; pc = c; while (pa <= a + lena - 1 && pb <= b + lenb - 1) { if (*pa <= *pb) *pc++ = *pa++; else *pc++ = *pb++; sum++; } while (pa <= a + lena - 1) *pc++ = *pa++; while (pb <= b + lenb - 1) *pc++ = *pb++;         *pc = '\0'; if((fp=fopen("C2.txt","w"))==NULL) { printf("can't open file C2\n"); return 1; } fputs(c, fp); fclose(fp); if((fp=fopen("C2.txt","r"))==NULL) { printf("can't open file C2\n"); return 1; } while (fgets(c,41,fp)!=NULL) { printf("the content of file C2:"); printf("%s\n", c); } while(ch= fgetc(fp) != EOF)         {                 if(ch>=48 &&ch<=57)//数字的ASCII码                 {                          number++;                 }         if((ch>=65&&ch<=90) || (ch>=97&&ch<=122))//字母的ASCII码         {             character++;         }         if(ch == 32)//空格的ASCII码         {             space++;         }         total++;         } printf("数字 = %d 字母 = %d 空格 = %d 字符数 = %d\n",number,character,space,total); printf("文件C2中包含的字符数：%d\n",sum); return 0; }

user: user-2
content: #include<stdio.h> #include<string.h> #include <ctype.h>  int alpha_cnt, digit_cnt, space_cnt, other_cnt, total_cnt; void merge_sort(char *a, char *b, char *c);  void sort(char x[]) {     int len, i, j;     char temp;     len = strlen(x);     for(i=0;i<len-1;i++)         for(j=0;j<len-i-1;j++)             if (x[j]>x[j+1])             {                 temp = x[j]; x[j] = x[j + 1]; x[j + 1] = temp;             } }   int main() {     FILE *fp;     char a[21], b[21], c[41];     /*     int lena, lenb;     int sum=1;     int ch;     int number = 0;     int character = 0;     int space = 0;     int total = 0;     char *pa, *pb, *pc;     */     if((fp=fopen("A2.txt","r"))==NULL)     {         printf("can't open file A2\n");         return 1;     }     while(fgets(a,21,fp)!=NULL)     {         printf("the content of file A2:");         printf("%s\n", a);     }     fclose(fp);     if((fp=fopen("B2.txt","r"))==NULL)     {         printf("can't open file B2\n");         return 1;     }     while(fgets(b,21,fp)!=NULL)     {         printf("the content of file B2:");         printf("%s\n", b);     }     sort(a);     sort(b);      /*     lena = strlen(a);     lenb = strlen(b);     pa = a; pb = b; pc = c;     while (pa <= a + lena - 1 && pb <= b + lenb - 1)     {         if (*pa <= *pb)             *pc++ = *pa++;         else *pc++ = *pb++;         sum++;     }      while (pa <= a + lena - 1) {         *pc++ = *pa++;         sum++;     }      while (pb <= b + lenb - 1) {         *pc++ = *pb++;         sum++;     }     */     merge_sort(a, b, c);     printf("digit: %d, alpha: %d, other: %d\n", digit_cnt, alpha_cnt, other_cnt);     return 0; }  void merge_sort(char *a, char *b, char *c) {     int lena, lenb;     char *pa, *pb, *pc;      lena = strlen(a);     lenb = strlen(b);     pa = a; pb = b; pc = c;     while (pa <= a + lena - 1 && pb <= b + lenb - 1)     {         if (*pa <= *pb)             //*pc++ = *pa++;             *pc = *pa++;         else             //*pc++ = *pb++;             *pc = *pb++;         if (isdigit(*pc))             digit_cnt++;         else if (isalpha(*pc))             alpha_cnt++;         else if (isspace(*pc))             space_cnt++;         else             other_cnt++;         total_cnt++;         pc++;     }      while (pa <= a + lena - 1) {         *pc = *pa++;         if (isdigit(*pc))             digit_cnt++;         else if (isalpha(*pc))             alpha_cnt++;         else if (isspace(*pc))             space_cnt++;         else             other_cnt++;         total_cnt++;         pc++;     }      while (pb <= b + lenb - 1) {         *pc = *pb++;         if (isdigit(*pc))             digit_cnt++;         else if (isalpha(*pc))             alpha_cnt++;         else if (isspace(*pc))             space_cnt++;         else             other_cnt++;         total_cnt++;         pc++;     }  } 供参考～  注意一下fgets会将'\n'放到缓存里。