帮忙看下一段小程序
#include <stdio.h>main(){ FILE *fp; char c, str[256]; int i=0, no=0, line=0; if((fp=fopen("text.txt","w"))==NULL) // { printf("can`t open this file.\n"); exit(0); } printf("please input a string.\n"); while((c=getchar())!=EOF) { if(c>='a'&&c<='z') c-=32; // fputc(c, fp); // } fclose(fp); if((fp=fopen("text.txt", "r"))==NULL) { printf("can`t open this file.\n"); exit(0); } while(!feof(fp)) { c=fgetc(fp); // no++; if(c=='\n') line++; // } printf("line=%d character_no=%d\n", line, no); fclose(fp);}
if((fp=fopen("text.txt","wb"))==NULL) //\r\n 处理 { printf("can`t open this file.\n"); return ; }
[解决办法]