#include <stdio.h> #include <stdlib.h> #include <string.h> void myCount(char *filename); void maxLine(char *filename); int main(){ char *filename="D:/23.txt"; myCount(filename); maxLine(filename); return 1; } void myCount(char * filename){ FILE * fp; fp=fopen(filename,"r"); char ch; int countLine=1; int Uletters=0; int Sletters=0; int others=0; while( (ch=fgetc(fp))&&ch!=EOF ){//EOF是一个char常量 表示读到了文件末位 //printf("%c,",ch);//ok if(ch=='\n'){ countLine++; }else if(ch==' '){ }else if( ch>='a'&&ch<='z' ){ Uletters++; }else if( ch>='A'&&ch<='Z' ){ Sletters++; }else { others++; } } } void maxLine(char * filename){ FILE * fp; fp=fopen(filename,"r"); char temp[100]; char maxLine[100]; int max=0; while( !feof(fp) ){//用foef(fp)函数来判断是否是文件末尾 fgets(temp,100,fp);//实际上最多读入99个字符 因为读入的一行的末位要存放'\0' puts(temp); if(strlen(temp)>max){ max=strlen(temp); strcpy(maxLine,temp); } } printf("maxLine is %s",maxLine); }
转载于:https://www.cnblogs.com/cart55free99/archive/2013/03/25/2981043.html