⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test6_4.txt

📁 Linux下的C语言编程
💻 TXT
字号:
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>

#define NEWFILE (O_WRONLY|O_CREAT|O_TRUNC)

int main(void)
{
    	char buf1[ ]={"abcdefghij"};
    	char buf2[ ]={"1234567890"};
	int fd;
	int length;

	if(fd=open("test.hole", NEWFILE, 0600)==-1)
	{
    		printf("ERROR, OPEN WRITE FILE FAILED: \n", sys_errlist[errno]);
    		exit(255);
	}

	length=strlen(buf1);
    	if(write(fd, buf1,length)!=length)
    	{
    		printf("ERROR, OPEN WRITE FILE FAILED: \n", sys_errlist[errno]);
    		exit(255);
	}

    	if(lseek(fd, 50, SEEK_SET)==-1)
    	{
    		printf("ERROR, LSEEK FAILED: \n", sys_errlist[errno]);
        	exit(255);
    	}

	length=strlen(buf2);
    	if(write(fd, buf2,length)!=length)
    	{
    		printf("ERROR, OPEN WRITE FILE FAILED: \n", sys_errlist[errno]);
    		exit(255);
	}

	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -