- 论坛徽章:
- 0
|
(原标题为:求解:一个菜鸟编程中的问题!)
编写了一个shell命令cp
代码如下:
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#define maxOnce 1024
int main(int argc,char * argv[])
{
int fdsrc,fddist;
char buf[maxOnce];
char buf1[maxOnce];
int size;
if(argc!=3)
printf("error for input\n");
if((fdsrc=open(argv[1],O_RDONLY)==-1)
perror("error for open\n ");//出错
if((fddist=creat(argv[2],S_IREAD | S_WRITE)==-1)
perror("error for creat");
while((size=read(fdsrc,buf,maxOnce))>0)
{
if(write(fddist,buf1,maxOnce)!=size)
perror("error for write\n");
}
if(close(fdsrc)==-1||close(fddist)==-1)
perror("error for close\n");
return 0;
}
编译连接
[melon@localhost linuxApp]$ gcc -lm cp.c -o cp
cp.c: 在函数 ‘main’ 中:
cp.c:15: 错误:expected ‘)’ before ‘perror’
cp.c:26: 错误:expected declaration or statement at end of input
怎么想也不知道错在那里,大侠能指点下吗?
我看了半天也不知道这个是错在那里!
编写了其他的shell命令也出现了这个错误,希望大侠们指点下!
迷惑ing
[ 本帖最后由 langue 于 2006-12-27 20:35 编辑 ] |
|