#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#define AS 40
char* zx(char* cv, int n);
int main(void)
{
char qw[AS];
char ty[AS];
FILE* as;
errno_t er;
char *ch;
char yy;
int w=0;
printf("请输入文件名:");
zx(qw, AS);
if ((er = fopen_s(&as, qw, "w+")) != 0)
{
printf("文件打开失败!!");
exit(EXIT_FAILURE);
}
if (er == 0)
{
printf("请输入文件内容:");
fgets(ty, AS - 1, stdin);
ch = ty;
while (*ch != '\0')
{
yy = toupper(*ch);
if (w == 4)
{
fprintf(as, "\n");
w = 0;
}
fprintf(as, "%c",yy);
w++;
ch++;
}
}
puts("文件成功!!");
fclose(as);
return 0;
}
char* zx(char* cv, int n)
{
char* bn;
char* nm;
bn = fgets(cv, n - 1, stdin);
if (bn)
{
nm = strchr(cv, '\n');
if (nm)
{
*nm = '\0';
}
else
while (getchar() != '\n')
{
continue;
}
}
return bn;
}