如题,在调试C语言程序时含有一个fopen()函数,创建了一个名为“words”的文件,可以用Windows的记事本打开并编辑,我又创建了一个名字是“file”的TXT文件(内容和“words”相同),用编译器生成的.EXE程序,可以处理自动生成的words,却不能处理自己新建的file文件,请问是应为格式不一样吗?如果是文件格式不对,应该使用哪种格式的文件才能成功打开呢?
程序清单:
/*reverse.c--反序显示一个文件*/
#include <stdio.h>
#include <stdlib.h>
#define CNTL_Z '\032'
#define SLEN 50
int main(void)
{
char file[SLEN];
char ch;
FILE * fp;
long count,last;
puts("Enter the name of the file to be processed:");
gets(file);
if((fp = fopen(file,"rb")) == NULL)
{
printf("reverse can't open %s\n",file);
exit(1);
}
fseek(fp,0L,SEEK_END);
last = ftell(fp);
for(count = 1L;count <= last;count++)
{
fseek(fp,-count,SEEK_END);
ch = getc(fp);
if(ch != CNTL_Z && ch != '\r')
putchar(ch);
}
putchar('\n');
fclose(fp);
return 0;
}

程序清单:
/*reverse.c--反序显示一个文件*/
#include <stdio.h>
#include <stdlib.h>
#define CNTL_Z '\032'
#define SLEN 50
int main(void)
{
char file[SLEN];
char ch;
FILE * fp;
long count,last;
puts("Enter the name of the file to be processed:");
gets(file);
if((fp = fopen(file,"rb")) == NULL)
{
printf("reverse can't open %s\n",file);
exit(1);
}
fseek(fp,0L,SEEK_END);
last = ftell(fp);
for(count = 1L;count <= last;count++)
{
fseek(fp,-count,SEEK_END);
ch = getc(fp);
if(ch != CNTL_Z && ch != '\r')
putchar(ch);
}
putchar('\n');
fclose(fp);
return 0;
}

