高分求帮改正错误
程序代码:
#include "stdio.h" #include "string.h" #define SIZE 1000 typedef struct ParaCount Count; struct ParaCount { int Integer; float Float; char Word; char other; }; main() { char FILENAME[20]; char c; char string[SIZE]; int flag=0; int word=0,integer=0,Float=0,other=0; int i=0,j=0,m=0,n=0; int num=0; float temp[SIZE][20]; Count count[SIZE]; FILE *fp; //提示及输入文档 printf("Enter thr name of your file \(less than 20 letters\)\n"); scanf("%s",FILENAME); printf("Enter a paragraph of a text to be tested\t\n\(start with a space and end with Ctrl+z\)\n"); printf("\n"); if((fp=fopen(FILENAME, "wb"))==NULL) { printf("error!\n"); exit(0); } c=getchar(); while(c!=EOF) { fputc(c,fp); c=getchar(); } rewind(fp); if((fp=fopen(FILENAME, "r"))==NULL) { printf("error!\n"); exit(0); } c=fgetc(fp); //计数 while(c!=EOF) { string[i]=c; i++; c=fgetc(fp); } for(j=0;j<i;j++) { printf("%c",string[j]); } while(j<i) { if((string[j]>='a'&&string[j]<='z')||(string[j]>='A'&&string[j]<='Z')) { word++; while(string[j]!=' ') { j++; count[word].Word[n]=string[j]; n++; } } j++; n=0; else if(string[j]>='0'&&string[j]<='9') { num++; while(string[j]!=' ') { j++; temp[num][n]=string[j]; n++; } for(m=0;m<n;m++) { if(temp[num][m]!='.'&&temp[num][m]!='%'); continue; else { flag=1; return flag; } } if(flag) { Float++; count[Float].Float=temp[num]; } else { integer++; count[integer].Integer=temp[num]; } } j++; n=0; else { while(string[j]!=' ') { j++; count[other].other=string[j]; other++; } } j++; } printf("%d",word); for(i=0,i<=word,i++) printf("%s",count[word].Word); printf("%d",integer); for(i=0,i<=integer,i++) printf("%s",count[integer].Integer); printf("%d",Float); for(i=0,i<=Float,i++) printf("%s",count[Float].Float); printf("%d",other); for(i=0,i<=other,i++) printf("%s",count[other].other); } fclose(fp); }题目要求Write a program : To count the number of following data:
1. word, consist of letter, a~z, and A~Z
2. number, consist of 0~9 and “.”, “%”, meanwhile, judge the type of it:
a) int
b) float
3. Special character, such as “@, ^,! ,? , /, &, *, (,)” etc.
A paragraph of a text, that is to be tested and analyzed, is entered from the keyboard. The text file is created by the program first. Please use struct and pointer to record statistically and, after tidy them up, please display the number of each type and the classified data.