- 论坛徽章:
- 0
|
下面程序在linux fc7 下用gcc编译
#include<stdio.h>
#include<errno.h>
#include<sys/stat.h>
#include<unistd.h>
#include<stdlib.h>
#include<fcntl.h>
main(int argc,char * argv[] )
{
int fd1,fd2,l;
void * tp;
char *path;
char buf[50];
struct stat ps;
path=buf;
printf("enter a path:");
scanf("%s",path);
printf("%s",argv[1]);
fstat(fd1.&ps);
if(fd1=(open(argv[1],O_RDONLY))==-1) {printf("error1");exit(1);}
if(fd2=(open(path,O_CREAT|O_WRONLY))==-1) {printf("error2");exit(1);}
l=ps.st_size;
tp=malloc(l);
if (tp==NULL) {printf("erroe_7");}
if(read(fd1,tp,l)!=l) {perror("read error3");exit(1);}
write(fd2,tp,l);
if(close(fd1)==-1||close(fd2)==-1)
{printf("error4");exit(1);}
}
错误情况
alhost jun]# gcc aa.c
[root@localhost jun]# ./a.out /jun/41
enter a path:/jun/63
read error3: Bad address
/jun/41error_[root@localhost jun]#
请问这个那里错误了
[ 本帖最后由 shiyangb 于 2007-12-13 21:59 编辑 ] |
|