调试C语言fopen(words,“w”)函数在win7系统里创建的文件格式
codeblocks吧
全部回复
仅看楼主
level 3
Lucifer_z_tl 楼主
如题,在调试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;
}
2017年07月24日 08点07分 1
level 1
应该输入file.txt,你最好设置一下你的文件管理器,让它显示文件的全名,在网上搜索一下设置方法.
——我喂自己袋盐
>>Mozilla/5.0 (Windows NT 10.0; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0
2017年07月25日 04点07分 2
1