C言語では、指定されたディレクトリにファイルを保存するには

目的:入力が指定されたディレクトリ内のファイルに保存されます

ステップ:

①パス入力します。
②テキスト入力を

結果は以下の通りであります:

ここに画像を挿入説明
コードは以下の通りであります:

#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;
}
公開された53元の記事 ウォン称賛18 ビュー10000 +

おすすめ

転載: blog.csdn.net/YUEXILIULI/article/details/103749771