文件操作

//  vs2013操作

//可以用fopen 函数对文件进行操作

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include<string.h>

int main(){
char s[5000] = { 0 };
FILE *p = fopen("F:\BaiduYunDownload\hello.txt","w");
//文件打开的方式 路径+文件名 读写状态
int sum = 0;
while (1){
gets(s);//gets 可以有空格 scanf不能用空格

if (strcmp(s, "finish") == 0)
break;//结束命令
int len = strlen(s);//获取字符串的长度
sum += len;
s[len] = ' ';//换行
fputs(s, p);

}

fclose(p);
printf("共输入%d个字符"sum);
printf("end ");
system("pause");
return 0;

}

原文地址:https://www.cnblogs.com/liaoxianfu/p/6111185.html