?? test6_2.txt
字號:
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#define NEWFILE (O_WRONLY|O_CREAT|O_TRUNC)
#define SIZE 80
int write_buffer(int fd, char *buf, int count);
int main(void)
{
int outfile;
char filename[ ]={"test.dat"};
char buffer[SIZE];
if(outfile=open(filename, NEWFILE, 0640)==-1)
{
printf("ERROR, OPEN FILE FAILED! \n");
exit(255);
}
while(!strcmp(buffer,"quit"))
{
gets(buffer);
if(write_buffer(outfile, buffer, SIZE)==-1)
{
printf("ERROR,WRITE FAILED: \n",sys_errlist[errno]);
exit(255);
}
}
close(outfile);
return 0;
}
int write_buffer(int fd, char *buf, int count)
{
int i,n;
char write_buf[SIZE];
int write_offset=0;
for(i=0; i<count; ++i)
{
write_buf[write_offset++]=*buf++;
if(write_offset==SIZE)
{
write_offset=0;
n=write(fd, write_buf, sizeof(write_buf));
if(n!=SIZE)
return -1;
}
}
return -1;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -