2008
01-09

請高手給點意見…

/*a new programme, recover the old programme*/
#include<stdio.h>
int main(void){
    FILE*input,*output;
    output=fopen(“report.txt”,”w”);
    char filename[30];
    char find[30];/*search the number of any word in the article*/
    char string[30];/*count the words*/
    int nextline=0;
    int word=0;
    int fow=0;
    int sentence=0;
    int count[150]={0};/*number of letters storage areas, 0 is the being number*/
    int cmp, findstrlen, searchstrlen, findcount=0, many=1;/*use them in compare words*/
    int code;/*ascii code, use it in count[code], to name the "count" array*/
    int list, roll;
    printf("project   9-1-2008\n");
    printf("--------------------------------------------------------------------------\n");
    printf("This is a simple article Analyzer.\n");
    printf("All information will be exported to the \"report.txt\".\n\n\n");
    printf("Output as follows:\n");
    printf("1 . The total number of letters.\n");
    printf("2 . The total number of words.\n");
    printf("3 . The total number of sentences.\n");
    printf("4 . The total number of specific words.\n");
    printf("--------------------------------------------------------------------------\n");
    printf("Input the file name(e.g. abc.txt) : ");
do{
    if(fow>=1){
               printf("\nOpen the file failure! Check the real file name and input the file name again.\n");
               printf("Filename : ");
               }
    scanf("%s",filename);
    input=fopen(filename,"r");
    fow++;
}while(input==NULL);
    input=fopen(filename,"r");
    printf("\n\n\n");
    fprintf(output,"The article(%s).\n",filename);
    fprintf(output,"--------------------------------------------------------------------------\n");
while((code=fgetc(input))!=EOF){
                                printf("%c",code);
                                fprintf(output,"%c",code);
                                count[code]++;/*increase number of letters*/
                                if(code==33||code==46||code==58||code==59||code==63){
                                                                                   sentence++;/*increase number of sentence*/
                                                                                   }
                                }
fclose(input);
fprintf(output,"\n--------------------------------------------------------------------------\n");
printf("\n");
/*count the words in the article(read the input file again)*/
/*open the input file again*/
    input=fopen(filename,"r");
while(fscanf(input,"%s",string)!=EOF){
                                      word++;/*increase number of word*/
                                      }
fclose(input);
/*output*/
fprintf(output,"The total number of letters : \n");
for(list=65,roll=0;list<=122;list++){
    roll++;
    if(roll==4||list==90){
                         nextline=10;
                         roll=0;
                         }else{
                              nextline=32;
                              }
    if(list==91){
                list=list+6;
                }
                fprintf(output,"%c : %3d    %c",list,count[list],nextline);
}
fprintf(output,"\n");
fprintf(output,"The total number of words : %d\n\n",word);
fprintf(output,"The total number of sentences : %d\n\n",sentence);
fprintf(output,"The total number of specific words : \n");
printf("\n\n\n");
printf("Input the specific words.\n");
printf("Input '.' to end the programme.\n\n\n");
/*find any words*/
do{
              findcount=0;
              printf("The no.%d word is ",many);
              scanf("%s",find);
              findstrlen=strlen(find);
              many++;
              input=fopen(filename,"r");
while(fscanf(input,"%s",string)!=EOF){
                                      searchstrlen=strlen(string);
                                      if(string[searchstrlen-1]==32||string[searchstrlen-1]==34||string[searchstrlen-1]==39||string[searchstrlen-1]==44||string[searchstrlen-1]==46||string[searchstrlen-1]==58||string[searchstrlen-1]==59||string[searchstrlen-1]==63){
                                                                     string[searchstrlen-1]=0;
                                                                     }
                                      if(string[searchstrlen-2]==32||string[searchstrlen-2]==34||string[searchstrlen-2]==39||string[searchstrlen-2]==44||string[searchstrlen-2]==46||string[searchstrlen-2]==58||string[searchstrlen-2]==59||string[searchstrlen-2]==63){
                                                                     string[searchstrlen-2]=0;
                                                                     }
                                      if(string[searchstrlen-3]==32||string[searchstrlen-3]==34||string[searchstrlen-3]==39||string[searchstrlen-3]==44||string[searchstrlen-3]==46||string[searchstrlen-3]==58||string[searchstrlen-3]==59||string[searchstrlen-3]==63){
                                                                     string[searchstrlen-3]=0;
                                                                     }
                                      cmp=strcmp(find,string);
                                      if(cmp==0){
                                                findcount++;
                                                }
                                      }
                                      if(strcmp(find,".")!=0){
                                                    fprintf(output,"%s : %3d\n",find,findcount);
                                                    }else if(strcmp(find,".")==0&&many==2){
                                                          fprintf(output,"You have not any words to find.\n");
                                                          }
                                      fclose(input);
                                      }while(strcmp(find,".")!=0);
printf("\n\nFinished output.\nNow you can check the \"report.txt\".\n\n");
fprintf(output,"--------------------------------------------------------------------------\n");
fclose(output);
system("pause");
return 0;
}
/*diary*/


留下一个回复