📄 file操作1.cpp
字号:
/*
程序名称: 文件操作
使用函数: fopen, fclose, fputc, fgetc, feof
程序功能: 测试文件基本函数的使用
日期: 2008-02-28
作者: zuojianhua
*/
#include <stdio.h>
#include <string.h>
main()
{
FILE *fp = NULL;
// fp = fopen("c:\\zuojianhua\\data.txt","w+");
fp = fopen("c:\\zuojianhua\\data.txt","a");
// if( ferror(fp) != 0 )
if( !fp )
{
return 0;
}
char c;
for(int i=0; i<10; i++)
{
c = getchar();
fputc(c, fp);
}
fclose(fp);
fp = fopen("c:\\zuojianhua\\data.txt","r");
printf("=========\n");
/*
// 读取文件方式1
for(i=0; i<10; i++)
{
c = fgetc(fp);
putchar(c);
}
*/
// 读取文件方式2
while(!feof(fp))
{
c = fgetc(fp);
putchar(c);
}
///*
// 读取文件方式3
while( (c=fgetc(fp)) != EOF )
{
putchar(c);
}
//*/
fclose(fp);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -