本文主要是介绍ftell//fopen//fseek//test ok,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
fopen的使用
如果myfile.txt文件的权限是111, 文件也是可以打开的
#include <stdio.h>int main ()
{FILE * pFile;long size;//如果myfile.txt文件的权限是111, 文件也是可以打开的pFile = fopen ("myfile.txt","rb");if (pFile==NULL) {perror ("Error opening file");}else{fseek (pFile, 0, SEEK_END); // non-portablesize=ftell (pFile);fclose (pFile);printf ("Size of myfile.txt: %ld bytes.\n",size);}return 0;
}
userdeMacBook-Air:test userfei$ touch ftell.cpp
userdeMacBook-Air:test userfei$ vi ftell.cpp
userdeMacBook-Air:test userfei$ g++ ftell.cpp
userdeMacBook-Air:test userfei$ touch myfile.txt
userdeMacBook-Air:test userfei$ echo "11111111111"> myfile.txt
userdeMacBook-Air:test userfei$ cat myfile.txt
11111111111
userdeMacBook-Air:test userfei$ ./a.out
Size of myfile.txt: 12 bytes.
userdeMacBook-Air:test userfei$
这篇关于ftell//fopen//fseek//test ok的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!