#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define AS 200
char* ty(char* df, int n);
int main(void)
{
FILE* as;
char qw[AS];
char zx[AS];
char ch;
errno_t er;
printf("请输入文件名:");
ty(qw, AS);
if ((er = fopen_s(&as, qw, "w+")) != 0)
{
printf("文件打开失败");
exit(EXIT_FAILURE);
}
if (er == 0)
{
printf("文件创建成功!!\n文件名为:%s\n", qw);
printf("请输入文件内容:");
fgets(zx, AS - 1, stdin);
fprintf(as, "%s", zx);
}
fclose(as);
return 0;
}
char* ty(char* df, int n)
{
char* fine;
char* er;
er = fgets(df, n - 1, stdin);
if (er)
{
fine = strchr(df, '\n');
if (fine)
{
*fine = '\0';
}
else
while (getchar() != '\n')
{
continue;
}
}
return er;
}
12-15
1380