ssize_tread(int fd,void * buf, size_tcount);
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#define FileName "mm"
#define WriteNum 128
#define ReadNum 12
//ssize_t read(int fd, void *buf, size_t count);
//ssize_t write(int fd, const void *buf, size_t count);
//int open(const char *pathname, int flags);
//int open(const char *pathname, int flags, mode_t mode);
int main()
{
int fd;
char WriteBuffer[WriteNum]={0};
char *test="hello world ";
char ReadBuffer[ReadNum]={0};
if(WriteNum < (strlen(test)+1))
{
printf("error:WriteBuffer less than test\n");
return -1;
}
strcpy(WriteBuffer,test);
fd = open("FileName",O_RDWR|O_CREAT,0644);
if(fd==-1)
{
printf("open file failed!\n");
perror("why");
return 0;
}
printf("open file success\n");
//write(fd,&WriteBuffer[0],11);
read(fd,&ReadBuffer[0],11);
printf("%s\n",ReadBuffer);
close(fd);
return 0;
}