王杰IOday5

#include <stdio.h>
#include <string.h>
#include <stdlib.h>	
#include <my_head.h>
void*copy(void* arg)
{
	int fd=open("./1.jpg",O_RDWR);
	int fd2=open("./2.jpg",O_RDWR|O_APPEND);
	ssize_t res=0;
	char buf[20]="";
	lseek(fd2,*(int*)arg,SEEK_SET);
	while(1){
		res=read(fd,buf,sizeof(buf));
		if(res==0){
			break;
		}
		write(fd2,buf,res);
	}
	close(fd2);
}
int main(int argc, const char *argv[])
{
	int fd=open("./2.jpg",O_RDWR|O_CREAT|O_APPEND,0664);
	close(fd);
	int fd1=open("./1.jpg",O_RDWR);
	int fd2=open("./2.jpg",O_RDWR|O_APPEND);
	ssize_t res=0;
	off_t len=lseek(fd1,0,SEEK_END);
	lseek(fd1,0,SEEK_SET);
	ssize_t sum=0;
	char buf[20]="";
	while(1){
		res=read(fd1,buf,sizeof(buf));
		sum+=res;
		if(sum<=(len/2))
		{
			write(fd2,buf,res);
		}
		else{
			write(fd2,buf,res);
			break;
		}
	}
	pthread_t tid;//创建分支线程
	int len1=lseek(fd1,0,SEEK_CUR);
	if(pthread_create(&tid,NULL,copy,(void*)&len1)!=0){
		fprintf(stderr,"fail _%d_\n",__LINE__);
	}
	pthread_join(tid,NULL);
	close(fd1);
	close(fd2);
	return 0;
}
#include <stdio.h>
#include <string.h>
#include <stdlib.h>	
#include <my_head.h>
char buf[]="1234567";
void* daozhi(void* arg)
{
	char *p = buf;
	int size = strlen(buf);
	while(1){
		int j = size-1;
		for(int i = 0; i < j; i++){
			char temp = *(p+i);
			*(p+i) = *(p+j);
			*(p+j) = temp;
			j--;
		}
	}
}
int main(int argc, const char *argv[])
{
	pthread_t tid;
	if(pthread_create(&tid,NULL,daozhi,NULL)!=0)
	{
		fprintf(stderr,"fault__%d__\n",__LINE__);
		return -1;
	}
	//char buf[]="1234567";
	while(1)
	{
		if(strcmp("1234567",buf)==0||strcmp("7654321",buf))
		printf("%s\n",buf);
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值