第一部份:文本的写入
一、在tcc目录下建立一个c文件(c文件建立参考我的另一篇文章https://blog.youkuaiyun.com/taw19960426/article/details/89417875
),
文件内容为下:
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *fp;
char ch,filename[20];
printf("please input the filename you want to write:");
scanf("%s",filename);
if (!(fp=fopen(filename,"wt+"))){
printf("Failed to open file");
exit(0);
}
printf("please input the sentences:");
ch=getchar();
ch=getchar();
while( ch !=EOF)
{
fputc(ch,fp);
ch=getchar();
}
fclose(fp);
}
二、用tcc运行,会产生.exe的程序
三、运行.exe的程序,写入后回车,再ctrl+z(EOF)
第二部份:文本的读出
一、编写c文件,内容如下:
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *fp;
char ch,filename[20];
printf("please input the filename you want to write:");
scanf("%s",filename);
if (!(fp=fopen(filename,"r"))){
printf("Failed to open file");
exit(0);
}
while( ch !=EOF)
{
ch=fgetc(fp);
putchar(ch);
}
fclose(fp);
}
二、tcc运行,生成.exe
三、运行.exe