c语言——vi编辑器(第一版)
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(int argc ,char * argv[])
{
char fileName[256];
printf("请您输入一个需要创建的文件:\n");
scanf("%s", fileName);
getchar();
FILE * fp = fopen(fileName, "w");
if (fp == NULL)
{
return -1;
}
char buf[1024];
while (1)
{
memset(buf, 0, 1024);
fgets(buf, 1024, stdin);
if (strncmp("comm=exit", buf,9) == 0)
{
break;
}
int i = 0;
while (buf[i] != '\0')
{
fputc(buf[i++], fp);
}
}
fclose(fp);
system("pause");
return EXIT_SUCCESS;
}
# c语言——vi编辑器(第二版)
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main04()
{
char fileName[256];
printf("请输入文件名:\n");
scanf("%s", fileName);
getchar();
FILE * fp = fopen(fileName, "w");
if (!fp)
return -1;
char buf[1024];
while (1)
{
memset(buf, 0, 1024);
fgets(buf, 1024, stdin);
if (!strncmp("comm=exit", buf, 9))
break;
int i = 0;
while (buf[i])
fputc(buf[i++], fp);
}
fclose(fp);
system("pause");
return EXIT_SUCCESS;
}