1a.c

来自「liunx下的shell实现;进程、线程同步的实现;I/O系统调用的比较(mma」· C语言 代码 · 共 67 行

C
67
字号
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#define N 1024struct buffer{char buff[N];struct buffer *next;};int main(void){void shuchu(struct buffer *q,int j);int fpin;struct buffer *head=NULL,*p;int i=1,j;fpin=open("text",O_RDONLY);if(fpin<0)	{	printf("can't open this file\n");	return 1;	}printf("%d",fpin);while(i){p=(struct buffer*)malloc(sizeof(struct buffer));if(head==NULL){p->next=NULL;head=p;}else{p->next=head;head=p;}j=i;i=read(fpin,p->buff,N);}close(fpin);shuchu(head,j);} void shuchu(struct buffer *q,int j){int fpout;int i,flag=0;char temp[N];fpout=open("text",O_WRONLY);do{for(i=N-1;i>=0;i--){temp[N-i-1]=q->buff[i];}q=q->next;if(flag==0)		{write(fpout,temp+1024-j,j);		flag=1;		}else		{		write(fpout,temp,N);		}}while(q!=NULL);close(fpout);}

⌨️ 快捷键说明

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