fopen_example.c.c
来自「linux下的程序开发(C语言实现):本程序主要实现文件的操作」· C语言 代码 · 共 16 行
C
16 行
//open file try.txt with readonly mode;.on failure print "fail to open file!" then return; otherwise print "open file successfully” then close the opened file
#include<stdio.h>
int main(int argc,char *argv[])
{
FILE *fp=NULL;
fp=fopen("try.txt","r"); //以只读形式打开文件try.txt
if(fp==NULL) //不成功则输出"fail to open file!\n"
{
printf("fail to open file!\n");
return -1;
}
printf("open file successfully!\n");
fclose(fp); //关闭已打开的文件
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?