閱讀743 返回首頁    go 阿裏雲 go 技術社區[雲棲]


fopen fclose 函數練習

程序代碼:

#include <stdio.h> #include <stdlib.h> int main() { FILE* fp = NULL; int a = 0; fp = fopen("data.txt","rt"); //打開文件 if(fp == NULL) { perror("data.txt"); exit(-1); } else { printf("succeed in opening the file!/n"); } fclose(fp); //關閉文件 return 0; } 

 

運行結果:

1、文件存在

 

$ ./test succeed in opening the file!  

 

2、文件不存在

$ ./test data.txt: No such file or directory

 

 

最後更新:2017-04-02 06:51:36

  上一篇:go 關於基於xfire webservice框架開發webservice的總結
  下一篇:go 大型項目使用Automake/Autoconf完成編譯配置(1)——提綱挈領