文件操作
2015-07-21 18:47
344 查看
/***************************************************************************************************************
Description :简单文件操作
Author : feng
Date :2015.0721
***************************************************************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#define SUCCESS 0
#define UNSUCCESS -1
int main()
{
int fp = 0;
int copy_to = 0;
char buffer[1024] = {0};
char temp[1024] = {0};
fp = open("hello",O_CREAT|O_RDWR,0755);
strcpy(buffer,"hello world");
write(fp,buffer,strlen(buffer));
close(fp);
fp = -1;
fp = open("hello",O_CREAT|O_RDWR,0755);
lseek(fp,strlen(buffer),SEEK_SET);
memset(buffer,0,sizeof(buffer));
printf("please enter the string : ");
fgets(buffer,sizeof(buffer),stdin);
write(fp,"\n",1);
write(fp,buffer,strlen(buffer));
memset(buffer,0,sizeof(buffer));
lseek(fp,0,SEEK_SET);
read(fp,buffer,sizeof(buffer));
copy_to = open("copy",O_CREAT|O_RDWR,0755);
write(copy_to,buffer,strlen(buffer));
close(copy_to);
return SUCCESS;
}
Description :简单文件操作
Author : feng
Date :2015.0721
***************************************************************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#define SUCCESS 0
#define UNSUCCESS -1
int main()
{
int fp = 0;
int copy_to = 0;
char buffer[1024] = {0};
char temp[1024] = {0};
fp = open("hello",O_CREAT|O_RDWR,0755);
strcpy(buffer,"hello world");
write(fp,buffer,strlen(buffer));
close(fp);
fp = -1;
fp = open("hello",O_CREAT|O_RDWR,0755);
lseek(fp,strlen(buffer),SEEK_SET);
memset(buffer,0,sizeof(buffer));
printf("please enter the string : ");
fgets(buffer,sizeof(buffer),stdin);
write(fp,"\n",1);
write(fp,buffer,strlen(buffer));
memset(buffer,0,sizeof(buffer));
lseek(fp,0,SEEK_SET);
read(fp,buffer,sizeof(buffer));
copy_to = open("copy",O_CREAT|O_RDWR,0755);
write(copy_to,buffer,strlen(buffer));
close(copy_to);
return SUCCESS;
}
相关文章推荐
- Objective-C的内省(Introspection)用法小结
- Objective-C中常用的结构体NSRange,NSPoint,NSSize(CGSize),NSRect实例分析
- Objective-C中NSLog输出格式大全
- Swift调用Objective-C编写的API实例
- Swift、Objective-C、Cocoa混合编程设置指南
- Objective-c代码如何移植为Swift代码 Objective-c代码转移到Swift过程介绍
- Swift调用Objective-C代码
- objective-c中生成随机数的方法
- 在Swift中使用Objective-C编写类、继承Objective-C类
- Swift能代替Objective-C吗?
- Objective-C 消息传递机制详解
- 在一个项目中同时使用Swift和Objective-C代码混合编程的方法
- vm安装mac os x 10.7 lion
- objective-c(一)
- objective-c(二)
- objective-c(三)
- objective-c(四)-基本数据类型以及循环和选择结构
- objective-c(六)文件分离,合成存取方法,方法多参数,局部变量,self使用(未完成)
- windows下objective-c的cocoa框架编程,可以有图形界面哟