VC6.0怎样改才能把结果输出到文本文件中保存?
#include"stdio.h"#include<fstream.h>voidmain(){charc;intn=0;intA1,A2,A3,A4,A5,A6;for(...
#include "stdio.h"
#include<fstream.h>
void main()
{char c;
int n=0;
int A1,A2,A3,A4,A5,A6;
for(A1=0;A1<=6;A1++)
for(A2=0;A2<=6;A2++)
for(A3=0;A3<=6;A3++)
for(A4=0;A4<=6;A4++)
for(A5=0;A5<=6;A5++)
for(A6=0;A6<=6;A6++)
{n=n+1;
printf("*%5d %2d %d %d %d %d %d ",n,A1,A2,A3,A4,A5,A6);
if (n%2==0) printf ("\n");
if (n%10==0)printf ("\n");
}
c=getchar();
} 展开
#include<fstream.h>
void main()
{char c;
int n=0;
int A1,A2,A3,A4,A5,A6;
for(A1=0;A1<=6;A1++)
for(A2=0;A2<=6;A2++)
for(A3=0;A3<=6;A3++)
for(A4=0;A4<=6;A4++)
for(A5=0;A5<=6;A5++)
for(A6=0;A6<=6;A6++)
{n=n+1;
printf("*%5d %2d %d %d %d %d %d ",n,A1,A2,A3,A4,A5,A6);
if (n%2==0) printf ("\n");
if (n%10==0)printf ("\n");
}
c=getchar();
} 展开
2个回答
2016-06-01 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
VC6.0把结果输出到文本文件中保存的方法是直接写入指定路径下的txt文件下。
以下程序将一个文件的内容附加到另一个文件中去。
设下面这个程序名为:linkfile.c
执行时可用:linkfile filename1 filename2形式的命令行运行,将文件filename2的内容附加在文件filename1之后。
#include <stdio.h>
#define SIZE 512
main(int argc,char *argv[])
{ char buffer[SIZE];
FILE *fp1,*fp2;
if(argc!=3)
{ printf("Usage: linkfile filename1 filename2<CR>\n");
exit(1);
}
if((fp1=fopen(argv[1],"a"))==NULL)
{ printf("The file %s can not be opened.\n",argv[1]);
exit(1);
}
if((fp2=fopen(argv[2],"r"))==NULL)
{ printf("The file %s can not be opened.\n",argv[2]);
exit(1);
}
while(fgets(buffer,SIZE,fp1)!=NULL)
printf("%s\n",buffer);
while(fgets(buffer,SIZE,fp2)!=NULL)
fputs(buffer,fp1);
fclose(fp1);
fclose(fp2);
if((fp1=fopen(argv[1],"r"))==NULL)
{ printf("The file %s can not be opened.\n",argv[1]);
exit(1);
}
while(fgets(buffer,SIZE,fp1)!=NULL)
printf("%s\n",buffer);
fclose(fp1);
}
以下程序将一个文件的内容附加到另一个文件中去。
设下面这个程序名为:linkfile.c
执行时可用:linkfile filename1 filename2形式的命令行运行,将文件filename2的内容附加在文件filename1之后。
#include <stdio.h>
#define SIZE 512
main(int argc,char *argv[])
{ char buffer[SIZE];
FILE *fp1,*fp2;
if(argc!=3)
{ printf("Usage: linkfile filename1 filename2<CR>\n");
exit(1);
}
if((fp1=fopen(argv[1],"a"))==NULL)
{ printf("The file %s can not be opened.\n",argv[1]);
exit(1);
}
if((fp2=fopen(argv[2],"r"))==NULL)
{ printf("The file %s can not be opened.\n",argv[2]);
exit(1);
}
while(fgets(buffer,SIZE,fp1)!=NULL)
printf("%s\n",buffer);
while(fgets(buffer,SIZE,fp2)!=NULL)
fputs(buffer,fp1);
fclose(fp1);
fclose(fp2);
if((fp1=fopen(argv[1],"r"))==NULL)
{ printf("The file %s can not be opened.\n",argv[1]);
exit(1);
}
while(fgets(buffer,SIZE,fp1)!=NULL)
printf("%s\n",buffer);
fclose(fp1);
}
展开全部
main(){
FILE *fpt;
char a[]="hello world!";
fpt = fopen("wendangming.txt","w");//创建并打开文档,并得到文件句柄
fprintf(fpt,"%s",a); //通过文件句柄写入内容
fclose(fpt); //关闭文件
}
FILE *fpt;
char a[]="hello world!";
fpt = fopen("wendangming.txt","w");//创建并打开文档,并得到文件句柄
fprintf(fpt,"%s",a); //通过文件句柄写入内容
fclose(fpt); //关闭文件
}
追问
请问你能把我这个程序改写来实现吗?
追答
我就不管你这程序是干什么用的了,要想把结果写入到 D:\TEST.TXT , 实现代码如下:
void main()
{
char c;
int n=0;
int A1,A2,A3,A4,A5,A6;
FILE *fpt;
fpt = fopen("D:\\test.txt","w");//创建并打开文档,并得到文件句柄
for(A1=0;A1<=6;A1++)
for(A2=0;A2<=6;A2++)
for(A3=0;A3<=6;A3++)
for(A4=0;A4<=6;A4++)
for(A5=0;A5<=6;A5++)
for(A6=0;A6<=6;A6++)
{
n=n+1;
char str[256];
sprintf(str, "*%5d %2d %d %d %d %d %d ",n,A1,A2,A3,A4,A5,A6);
fprintf (fpt, "%s", str);
if (n%2==0) fprintf (fpt,"\n");
if (n%10==0)fprintf (fpt,"\n");
}
fclose(fpt); //关闭文件
c=getchar();
}
嗯......
char str[256];
sprintf(str, "*%5d %2d %d %d %d %d %d ",n,A1,A2,A3,A4,A5,A6);
fprintf (fpt, "%s", str);
这部分,也可以这样写吧:
fprintf (fpt, "*%5d %2d %d %d %d %d %d ",n,A1,A2,A3,A4,A5,A6);
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询