目的:将输入内容保存在指定目录下的文件中
步骤:
①输入一个路径
②输入文字
效果如下:
代码如下:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<iostream>
#include<cstdio>
using namespace std;
#pragma warning(disable:4996)
int main()
{
char s[70];
char path[100];
printf("Input a path:\n");
scanf("%s",path);
getchar();
FILE* fp;
//cin >> paths;
if ((fp = fopen(path, "w")) == NULL) {
printf("Open the file failure...\n");
exit(0);
}
while (1) {
printf("Input a string...\ns=");
if (gets_s(s), strlen(s) < 70)
break;
printf("Too long, redo: ");
}
fputs(s, fp);
fclose(fp);
printf("\n");
return 0;
}