编写一个C程序来打印所有文件和文件夹
文件是记录的集合(或者)硬盘上永久存储数据的地方。
通过使用C命令,我们可以以不同的方式访问文件。
文件操作
以下是在C编程语言中可以执行的文件操作:
- 命名文件
- 打开文件
- 从文件中读取
- 向文件中写入
- 关闭文件
语法
打开和命名文件的语法如下:
FILE *File pointer;登录后复制
File pointer = fopen (“File name”, “mode”);登录后复制
FILE *fp; fp = fopen (“sample.txt”, “w”);登录后复制
int fgetc( FILE * fp );// read a single character from a file登录后复制
int fputc( int c, FILE *fp ); // write individual characters to a stream登录后复制
dr = opendir("."); if(dr!=NULL){ printf("List of Files & Folders:-
", d->d_name); } closedir(dr); }