你改成功了吗? &a NOT aDRIFT 写了:freeflag@freeflag-desktop:~/temp$ gcc test.c -o test -Wall
test.c: In function ‘main’:
test.c:16: warning: format ‘%d’ expects type ‘int *’, but argument 2 has type ‘int’
test.c:21: warning: passing argument 3 of ‘write’ makes integer from pointer without a cast
freeflag@freeflag-desktop:~/temp$
= 写了一段程序,其中有错误,思考良久,还是没有想通? =
- nobrain
- 帖子: 808
- 注册时间: 2005-08-25 13:58
- 来自: ustc
- 联系:
爱喝真猪奶茶的夜鸣猪
-
- 帖子: 177
- 注册时间: 2007-01-25 13:04
DRIFT 写了:代码: 全选
#include<stdio.h> #include<unistd.h> #include<sys/stat.h> #include<sys/types.h> #include<fcntl.h> #include<stdlib.h> int main(int argc,char *argv[]) { int fd,a,b; if(argc!=2) { printf("Error-1\n"); exit(1); } printf("Input:"); scanf("%d",&a); if((fd=open(argv[1],O_RDWR|O_CREAT))==-1) { printf("Error-2\n"); exit(2); } b=write(fd,"123456",a); if(b==-1) { printf("Error-3\n"); exit(3); } else { printf("%d\n",b); } if((close(fd))==-1) { printf("Error-4\n"); exit(4); } if((execlp("more","more",argv[1],NULL))<0) { printf("Error-5.\n"); exit(5); } return 0; }
总是有错,错误代码"Error-3"
写这个程序只是为了让我更好的理解write()函数的用法.谢谢大家的帮助!