请看这个程序:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
int main(void)
{
char ch,ch1;
long num;
FILE *fp;
fp=fopen("122802f.txt","r+");
if(fp==NULL)
printf("Open Failed! \n");
else
printf("Open Success! \n");
rewind(fp);
while((ch=getc(fp))!=EOF)
{
fseek(fp,-sizeof(char),SEEK_CUR);
putc(tolower(ch),fp);
num=ftell(fp);
printf("the num is %ld.\n ",num);
}
printf("Done! \n");
fclose(fp);
return 0;
}
我用的是 Dev-c, 测试的总是死循环,为什么? 是不是 122802f.txt 文件里的内容需要,比如结尾处 需要特殊处理?