还是同样的问题 Compiling... 1.cpp d:\c++\a\1.cpp(36) : fatal error C1010: unexpected end of file wh
#include<stdio.h>#include<string.h>#include<stdlib.h>voidmain(){chararray[257];charzh...
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void main()
{
char array[257];
char zhandian[6];
FILE *fp;
fp=fopen("20080101.txt","r");
while(fgets(array,256,fp)!=NULL)
{
char *ptr = array;
strncpy(zhandian,ptr+15,20);
FILE *fp1;
if((fp1=fopen("zhandian.txt","w"))!=NULL)
{
fputs(array,fp1);
fcolse(fp1);
memset(array,0,sizeof(array));
memset(zhandian,0,sizeof(zhandian));
}
else
{
char *filename;
sprintf(filename,"%s.txt",zhandian);
FILE *fp2;
fp2=fopen(filename,"w+");
fputs(array,fp2);
fclose(fp2);
memset(array,0,sizeof(array));
memset(zhandian,0,sizeof(zhandian));
}
}
fclose(fp);
}
用Microsoft Visual C++ 6.0进行编译的 展开
#include<string.h>
#include<stdlib.h>
void main()
{
char array[257];
char zhandian[6];
FILE *fp;
fp=fopen("20080101.txt","r");
while(fgets(array,256,fp)!=NULL)
{
char *ptr = array;
strncpy(zhandian,ptr+15,20);
FILE *fp1;
if((fp1=fopen("zhandian.txt","w"))!=NULL)
{
fputs(array,fp1);
fcolse(fp1);
memset(array,0,sizeof(array));
memset(zhandian,0,sizeof(zhandian));
}
else
{
char *filename;
sprintf(filename,"%s.txt",zhandian);
FILE *fp2;
fp2=fopen(filename,"w+");
fputs(array,fp2);
fclose(fp2);
memset(array,0,sizeof(array));
memset(zhandian,0,sizeof(zhandian));
}
}
fclose(fp);
}
用Microsoft Visual C++ 6.0进行编译的 展开
3个回答
2011-02-13
展开全部
//下面能通过编译!
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void main()
{
char array[257];
char zhandian[6];
FILE *fp;
fp=fopen("20080101.txt","r");
while(fgets(array,256,fp)!=NULL)
{
char *ptr = array;
strncpy(zhandian,ptr+15,20);
FILE *fp1;
if((fp1=fopen("zhandian.txt","w"))!=NULL)
{
fputs(array,fp1);
fclose(fp1);
memset(array,0,sizeof(array));
memset(zhandian,0,sizeof(zhandian));
}
else
{
char *filename;
sprintf(filename,"%s.txt",zhandian);
FILE *fp2;
fp2=fopen(filename,"w+");
fputs(array,fp2);
fclose(fp2);
memset(array,0,sizeof(array));
memset(zhandian,0,sizeof(zhandian));
}
}
fclose(fp);
}
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void main()
{
char array[257];
char zhandian[6];
FILE *fp;
fp=fopen("20080101.txt","r");
while(fgets(array,256,fp)!=NULL)
{
char *ptr = array;
strncpy(zhandian,ptr+15,20);
FILE *fp1;
if((fp1=fopen("zhandian.txt","w"))!=NULL)
{
fputs(array,fp1);
fclose(fp1);
memset(array,0,sizeof(array));
memset(zhandian,0,sizeof(zhandian));
}
else
{
char *filename;
sprintf(filename,"%s.txt",zhandian);
FILE *fp2;
fp2=fopen(filename,"w+");
fputs(array,fp2);
fclose(fp2);
memset(array,0,sizeof(array));
memset(zhandian,0,sizeof(zhandian));
}
}
fclose(fp);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
代码的语法应该没有问题了,可能是建的项目设置的问题,可能是被作为MFC程序,需要"stdafx.h",但mani()程序不能这样,可以重新建一个项目,我记不太清了,或者新建一个c++ source file就可以了。 文件名不用1.cpp,改成1.c试一试 。
你可以试一下,把main()中间的内容全部注释掉,看有没有问题。
void main()
{
return;
}
后面
char *filename;
sprintf(filename,"%s.txt",zhandian);
这句 char *filename 没有分配空间,运行会有错误:
改成 char filename[128];
你可以试一下,把main()中间的内容全部注释掉,看有没有问题。
void main()
{
return;
}
后面
char *filename;
sprintf(filename,"%s.txt",zhandian);
这句 char *filename 没有分配空间,运行会有错误:
改成 char filename[128];
来自:求助得到的回答
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询