[转]Linux文件操作函数open close read write等示例
来源:互联网 发布:eslyric源码 编辑:程序博客网 时间:2024/05/20 14:41
//fileopen.c
//fileopen2.c
//test_system_fprintf_fopen.c
//file-rw.c
#include<stdio.h>#include<string.h>#include<sys/types.h>#include<sys/stat.h>#include<fcntl.h>#include<unistd.h>int main(){ char temp[]="hello,abc!";int fd;char pathname[255];if((fd=open("fileopen.txt",O_WRONLY|O_CREAT,0640))==-1){printf("creat file wrong!");}int len=strlen(temp)+1;write(fd,temp,len);//若fd为0,或这里直接写0,则会输出到屏幕上而不写入文件中close(fd);}
//fileopen2.c
#include<sys/types.h> #include<sys/stat.h> #include<unistd.h> #include<fcntl.h> #include <stdio.h>int main() {int fa; int s=12;int len;char text[20]="hello,fileopen2!!!";fa=open("fileopen2.txt",O_WRONLY|O_CREAT,0640);//len = sprintf(text, "%d", s);write(fa,text,sizeof(text)); close(fa); }
//test_system_fprintf_fopen.c
#include<stdio.h>#include<stdlib.h>int main(){FILE *stream;char temp[255];char *a="hello,c!";stream=fopen("fprintf.txt","w");fprintf(stream,"%s\n",a);fprintf(stream,"sb,c++\n");sprintf(temp,"nl fprintf.txt");fclose(stream);printf("%s\n",temp);system(temp);//system函数参数可以为字符串指针或直接字符串system("nl fprintf.txt");exit(0);return 0;}
//file-rw.c
#include<stdio.h>#include<fcntl.h>#include<unistd.h>int main(){int fdr,fdw;char temp[255];char filepath[255];char fileto[255];printf("please input the filepath:");scanf("%s",filepath);if((fdr=open(filepath,O_RDONLY))==-1){printf("file not found,open failed!");return -1;}else{int r_size=read(fdr,temp,255);close(fdr);sprintf(fileto,"file-rw.txt");if((fdw=open(fileto,O_WRONLY|O_CREAT,0640))==-1){printf("open failed!");return -1;}else{int w_size=write(fdw,temp,r_size);//相当于复制了所输入文件.txt中的255个大小的字符串到新文件file-rw.txt中close(fdw);printf("have successfully copied 255 chars from \"%s\" to \"%s\"\n",filepath,fileto);}}return 0;}
- [转]Linux文件操作函数open close read write等示例
- Linux文件操作函数open close read write等示例
- linux文件操作函数(open、write、read、close)
- linux文件操作函数(open、write、read、close)
- linux文件操作函数(open、write、read、close)
- Linux文件操作 create/open/close/write/read函数
- linux文件操作API 函数open read write close
- 底层文件操作函数--open、close、write、read
- Linux基础编程-文件操作open,lseek,read,write,close
- Linux基础编程-文件操作open,lseek,read,write,close
- Linux基础编程-文件操作open,lseek,read,write,close
- linux文件操作open close read write lseek
- Linux 文件操作 open,lseek,read,write,close
- Linux-文件操作(open、write、read、close、iotcl)
- linux 基本文件操作-----creat open write read close
- Linux 文件IO函数(open/close/read/write/lseek)
- linux文件操作函数(open、write、read、close)可用于串口读写
- linux下 open() write() read() close函数
- MAC OS下配置wget
- 将一个Web页面转换成用户控件
- 如何在IIS中配置php
- SIP Session Timers
- 利用openssl进行base64的编码与解码
- [转]Linux文件操作函数open close read write等示例
- SIP扩展与相关RFC介绍
- UIApplicationDelegate 代理函数调用的时间(应用程序生命周期)
- 67000319
- 如何取出Dialog的标题栏
- Hadoop Streaming使用简介
- sqlite3中的数据类型
- SIP: From ,Contact, Via 和 Record-Route/Route head
- 杭州最新公交线路一览(150-)