LINUX 下,编程自学一:文件操作
来源:互联网 发布:淘宝购买失败系统异常 编辑:程序博客网 时间:2024/04/30 01:12
opendir.c
#include<stdio.h>#include<unistd.h>#include<sys/types.h>#include<sys/stat.h>#include<dirent.h>int main(){DIR *dir;struct dirent *ptr;struct statfilestat;dir = opendir("file");chdir("file");while((ptr = readdir(dir)) != NULL ){if(strcmp(ptr->d_name,".") == 0 || strcmp(ptr->d_name,"..") == 0)continue;stat(ptr->d_name,&filestat);printf("file name :%s\t size :%d\n",ptr->d_name,filestat.st_size);}return 0;}
stat.c(文件状态)
#include<stdio.h>#include<sys/stat.h>#include<unistd.h>int main(){struct stat buf;stat("stat.c",&buf);printf("size = %d\n",buf.st_size);return 0;}
filefd.c(open,lseek等就用)
#include<stdio.h>#include<sys/types.h>#include<stdio.h>#include<unistd.h>#include<sys/stat.h>#include<fcntl.h>int main(){char buf[] = "This is test file";int fd ;fd = open("testfile",O_CREAT|O_RDWR);perror("open");write(fd,buf,sizeof(buf));perror("write");lseek(fd,100,SEEK_SET);perror("lseek");close(fd);sleep(1);printf("\n");fd = open("testfile",O_RDWR);perror("open");char buf_1[128];read(fd,buf_1,128);printf("buf_1 = %s\n",buf);close(fd);return 0;}
0 0
- LINUX 下,编程自学一:文件操作
- LINUX 下,编程自学一:单一C/S 通信
- Linux下C编程入门笔记——文件IO操作(一)
- linux下系统编程学习笔记之文件操作(一)
- LINUX 下,编程自学七:gethostbyname
- Linux 文件操作编程
- Linux-C高级编程(1)文件操作(一)
- linux c 编程实战:文件操作总结(一)
- linux操作系统下c语言编程入门 -- (3)文件操作
- linux操作系统下c语言编程入门--文件操作
- Linux下C语言编程--文件的操作
- Linux下C语言编程--文件的操作
- Linux下C语言编程--文件的操作
- Linux下C语言编程--文件的操作
- Linux下C语言编程--文件的操作
- 浅谈Linux下对文件操作编程的注意点
- Linux下C语言编程--文件的操作
- Linux下C语言编程——文件操作
- 1006.ZOJ问题
- 今天试着用公司的地址在google地图中找到他的经纬度
- Dialog无法warp_content
- c程序从编译链接到运行
- java当中多线程
- LINUX 下,编程自学一:文件操作
- shell中简单的字符串替换操作
- 精心收集面试必备的C#题库
- 错位排问题
- 常用的环境变量
- 【读书笔记】代码大全24章:重构
- ARM CP15协处理器
- 关于Textview的各种小笔记
- java中访问权限控制public protected default(friendly) 和private