
文件是记录的集合(或者)硬盘上永久存储数据的地方。
通过使用C命令,我们可以以不同的方式访问文件。
以下是在C编程语言中可以执行的文件操作:
打开和命名文件的语法如下:
FILE *File pointer;
例如,FILE * fptr;
File pointer = fopen (“File name”, “mode”);
例如,fptr = fopen("sample.txt", "r");
FILE *fp; fp = fopen (“sample.txt”, “w”);
读取文件的语法如下 −
采用JSP开发的办公自动化产品、基于B/S结构,运行环境:JDK v1.5、Tomcat v5.5、MySQL v4.1,三者均为以上版本其他相关内容:可视化流程设计: 流程支持串签、会签和分支流程,可以设置流程节点的修改、删除权限,并可指定流程中各个用户在表单中可以填写的域。智能表单所见即所得设计: 智能设计,自动在数据库中生成表格,方便优化程序 公共交流: 集论坛、博客、聊天室于一体文件柜:C
0
int fgetc( FILE * fp );// read a single character from a file
写入文件的语法如下 −
int fputc( int c, FILE *fp ); // write individual characters to a stream
The logic that we use to display the files and folders in current directory, where the program saved is explained below −
dr = opendir(".");
if(dr!=NULL){
printf("List of Files & Folders:-</p><p>");
for(d=readdir(dr); d!=NULL; d=readdir(dr)){
printf("%s</p><p>", d->d_name);
}
closedir(dr);
}Following is the C program for printing the files and folders in a directory −
#include<stdio.h>
#include<conio.h>
#include<dirent.h>
int main() {
struct dirent *d;
DIR *dr;
dr = opendir(".");
if(dr!=NULL) {
printf("List of Files & Folders:-</p><p>");
for(d=readdir(dr); d!=NULL; d=readdir(dr)) {
printf("%s</p><p>", d->d_name);
}
closedir(dr);
}
else
printf("</p><p>error while opening the directory!");
getch();
return 0;
}当上述程序被执行时,它产生以下输出:
List of Files & Folders:- . .. accessing array.c accessing array.exe accessing array.o bhanu.txt C Programs convert 2 digit no into english word.c convert 2 digit no into english word.exe convert 2 digit no into english word.o DATA delete vowels in string.c delete vowels in string.exe delete vowels in string.o emp.txt EVEN ex.c ex.exe ex.o example pro.c example pro.exe example pro.o fibbinoci serie.c fibbinoci serie.exe fibbinoci serie.o file file example1.c file example1.exe file example1.o file example2.c file example2.exe file example2.o implicit conversion.c implicit conversion.exe implicit conversion.o leap year.c leap year.exe leap year.o little n big endian.c little n big endian.exe little n big endian.o work out examples
以上就是编写一个C程序来打印所有文件和文件夹的详细内容,更多请关注php中文网其它相关文章!
C++高性能并发应用_C++如何开发性能关键应用
Java AI集成Deep Java Library_Java怎么集成AI模型部署
Golang后端API开发_Golang如何高效开发后端和API
Python异步并发改进_Python异步编程有哪些新改进
C++系统编程内存管理_C++系统编程怎么与Rust竞争内存安全
Java GraalVM原生镜像构建_Java怎么用GraalVM构建高效原生镜像
Python FastAPI异步API开发_Python怎么用FastAPI构建异步API
C++现代C++20/23/26特性_现代C++有哪些新标准特性如modules和coroutines
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号