从文件夹输入数据到控制台程序 c方式

https://www.cnblogs.com/Vincent-Bryan/p/6925639.html

1、从文件夹读入数据,并赋值给局部变量,再写入文件夹;

1) fscanf_s & fprintf

FILE *stream1, *stream2;
fopen_s(&stream1, "input.txt", "r"); 
fopen_s(&stream2, "output.txt", "w");

int n;
fscanf_s(stream1, "%d", &n);     //从stream1中读取一个int
fprintf(stream2, "%d", n);           //将int输出到stream2
fclose(stream1);
fclose(stream2);
return 0;

2) scanf_s

FILE *stream;
freopen_s(&stream, "TSP.txt", "r", stdin);
int n;

scanf_s("%d", &n);
for (int i = 0; i < n; i++)
scanf_s("%lf %lf", &p[i].x, &p[i].y);

 

posted @ 2019-04-08 23:09  kuaqi  阅读(272)  评论(0编辑  收藏  举报