关于生成文件的问题

searchsoft 2003-08-26 02:57:30
我打算写一个程序完成这样的功能,从一个文本文件中读出要生成的文件名的字符串,然后生成该文件。程序如下:#include <stdio.h>
#include <string.h>
#include <process.h>
void main()
{
FILE *fp1;
FILE *outfp[10];

int n = 0;
int o = 0;


char seg[100]="0";

char name[30];



fp1 = fopen("conf.txt", "r");
if (fp1 == NULL)
{
printf("open file fail!");
exit(0);
}

while (fp1 == EOF)
{
fgets(seg,sizeof(seg),fp1);
sscanf(seg,"%s",name);
outfp[n]=fopen(name,"w");
if (outfp[n] == NULL)
{
printf("open file fail!");
exit(0);
}
n++;
}

while (o <=n)
{
fclose(outfp[o]);
o++;
}
}//end of main

其中conf.txt文件的内容如下:
"o5021000.txt"
"o5022000.txt"
"o5023000.txt"
"o5024000.txt"
"o5025000.txt"
"o5026000.txt"
"o5027000.txt"
"o5028000.txt"

编译、执行,不能生成相应的文件。请问错在哪里?请指教,谢谢!
...全文
77 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
POLOM 2003-08-26
  • 打赏
  • 举报
回复
while (fp1 == EOF) --> while (!feof(fp1))

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧