-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstdcp.c
More file actions
31 lines (30 loc) · 739 Bytes
/
stdcp.c
File metadata and controls
31 lines (30 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*************************************************************************
> File Name: stdcp.c
> Author: jianghechao
> Mail: 591378033@qq.com
> Created Time: Wed 23 Apr 2014 11:54:43 PM CST
************************************************************************/
#include<stdio.h>
#include<unistd.h>
#include<fcntl.h>
#include<string.h>
#define MAX 100
int main()
{
int n = 0;
char buf[MAX];
while((n=read(STDIN_FILENO,buf,MAX))>0)
{
//printf("the bytes have read is %d\n",n);
buf[n] = 0;//此处一定记得加字符串结尾符
//printf("The bytes strlen calculate is %d\n",strlen(buf));
if(write(1,buf,n)!=n)
{
perror("write error\n");
}
//fflush(stdin);
}
if(n<0)
perror("read error\n");
return 0;
}