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