我编写了以下C程序将数据写入文件。程序编译正确但没有任何内容写入文件。如果需要,请提出修改。
#include <stdio.h>
#include <errno.h>
int main()
{
int i;
FILE *fopen(),*fp;
fp = fopen("D:\Satish_SharedSubstance\V13.4-CT_Testing\LONGRUN_Testing\writetest.txt","w");
/*Create a file and add text*/
if(fp!=NULL)
{
fprintf(fp,"GRP \n");
fprintf(fp,"groupname group_1 \n");
fprintf(fp,"groupcomment group_1\n");
fprintf(fp,"jobnet 255 \n");
fprintf(fp,";\n");
for (i=1;i<=255;i++)
{
fprintf(fp,"GNT \n");
fprintf(fp,"jobnetname jobnet_t%d\n",i);
fprintf(fp,"jobnetnumber %d\n",i);
fprintf(fp,";");
}
/*writes data to the file*/
fclose(fp); /*done!*/
}
else
{
printf("Error opening file\n");
}
return 0;
}
答案 0 :(得分:4)
fp = fopen("D:\Satish_SharedSubstance\V13.4-CT_Testing\LONGRUN_Testing\writetest.txt","w");
尝试在路径中将"\"
替换为"\\"
。
答案 1 :(得分:4)
两件事:
\
”替换为“\\
”。答案 2 :(得分:0)
您可以执行以下操作: -
FILE *fp = fopen("D:\\Satish_SharedSubstance\\V13.4-CT_Testing\\LONGRUN_Testing\\writetest.txt","w");