设文件alpha.txt在当前目录下——
代码文本:
#include "stdio.h"
int main(int argc,char *argv[]){
FILE *fp,*fpt;
char ch;
fp=fopen("alpha.txt","r+");
if(!fp || !(fpt=fopen("tfr.txt","w"))){
printf("Open the file failed, exit...\n");
return 0;
}
while((ch=fgetc(fp))!=EOF){
if(ch>='a' && ch<='z'){
fseek(fp,-1L,SEEK_CUR);
fputc(ch-=32,fp);
fputc(ch,fpt);
fseek(fp,0L,SEEK_CUR);
}
}
fclose(fp);
fclose(fpt);
fp=fopen("alpha.txt","a");
if(!fp || !(fpt=fopen("tfr.txt","r"))){
printf("Open the file failed, exit...\n");
return 0;
}
while((ch=fgetc(fpt))!=EOF)
fputc(ch,fp);
fclose(fp);
fclose(fpt);
remove("tfr.txt");
return 0;
}
供参考……