15,979
社区成员
发帖
与我相关
我的任务
分享
// 不好意思,修改一下Bug
#include <stdio.h>
int main(void)
{
char strBuf[4096];
long lenFile = 0;
FILE* fp = NULL;
*strBuf = 0;
if( !(fp = fopen("Save.txt", "a+")) )
{
return -1;
}
rewind(fp);
fseek(fp, 0L, SEEK_END);
lenFile = ftell(fp);
rewind(fp);
if( !lenFile ) // 第一次执行时输入一些文字用于显示
{
fgets(strBuf, 4096-1, stdin);
fwrite(strBuf, strlen(strBuf)-1, 1, fp);
}
else // 以后打开这个程序时,还可以显示这些文字
{
if( lenFile > (4096-1) )
{
lenFile = (4096-1);
}
fread(strBuf, lenFile, 1, fp);
strBuf[lenFile] = 0;
puts(strBuf);
}
fclose(fp);
return 0;
}
// 好久没有写C语言程序了!
#include <stdio.h>
int main(void)
{
char strBuf[4096];
long lenFile = 0;
FILE* fp = fopen("Save.txt", "a+");
*strBuf = 0;
rewind(fp);
fseek(fp, 0L, SEEK_END);
lenFile = ftell(fp);
rewind(fp);
if( !lenFile ) // 第一次执行时输入一些文字用于显示
{
fgets(strBuf, 4096-1, stdin);
fwrite(strBuf, strlen(strBuf)-1, 1, fp);
}
else // 以后打开这个程序时,还可以显示这些文字
{
if( lenFile > (4096-1) )
{
lenFile = (4096-1);
}
fread(strBuf, lenFile, 1, fp);
strBuf[lenFile] = 0;
puts(strBuf);
}
return 0;
}