컴파일러 warning: passing arg 1 of `sprintf' from incompatible pointer type
글쓴이: ch0nn0m / 작성시간: 목, 2009/07/16 - 5:42오후
파일전송 프로그램 만드는중에...
#include <stdio.h> #include <sys/types.h> #include <netinet/in.h> #include <fcntl.h> #include <sys/socket.h> #include <netdb.h> #define PORT 8888 #define BUFSIZE 1024 int main(int argc, char **argv) { int serv_sock, clnt_sock,fd,len,str; int filesize[128]; int buf[BUFSIZE]; long total; struct sockaddr_in server; struct sockaddr_in client; int client_size; if(argc !=2 ){ printf("Usage : %s Filename\n", argv[0]); exit(1); } serv_sock=socket(PF_INET, SOCK_STREAM, 0); memset(&server, 0, sizeof(server)); server.sin_family=AF_INET; server.sin_addr.s_addr=htonl(INADDR_ANY); server.sin_port=htons(PORT); if(bind(serv_sock,(struct sockaddr*)&server,sizeof(server))==-1) printf("bind() error\n"); if(listen(serv_sock, 5)==-1) printf("listen() error\n"); client_size=sizeof(client); clnt_sock=accept(serv_sock,(struct sockaddr*)&client,&client_size); printf("New Client Connected, Client IP : %s \n", inet_ntoa(client.sin_addr)); fd=open(argv[1],O_RDONLY,0); total=lseek(fd,0,SEEK_END); printf("Trans File Size %ld \n",total); sprintf(filesize,"%ld",total); write(clnt_sock, filesize, 128); lseek(fd,0,SEEK_SET); while((len = read(fd,buf,BUFSIZE)) > 0 ){ str=send(clnt_sock,buf,BUFSIZE,0); if(str == BUFSIZE) { total-=(long)str; if(total <= 0) { printf("성공적으로 보내기 완료\n"); str=0; break; } else { printf("성공 적으로 보내서 %ld 가 남았음\n",total); continue; } } else if(str < BUFSIZE) { total-=(long)str; if(total <=0) { printf("성공 완료\n"); break; } printf("비 성공적으로 %d 보냇당 그러나 %ld 만큼 남았다\n",len,total); } else if(str==-1); { printf("전송 실패\n"); exit(0); } } close(clnt_sock); close(fd); return 0; }
여기선
warning: passing arg 1 of `sprintf' from incompatible pointer type
#include <stdio.h> #include <sys/types.h> #include <netinet/in.h> #include <fcntl.h> #include <sys/socket.h> #include <netdb.h> #define PORT 8888 #define BUFSIZE 1024 int main(int argc, char **argv) { int sock,fd,str,len; int filesize[128]; int buf[BUFSIZE]; long total; struct sockaddr_in client; if(argc !=2 ){ printf("Usage : %s Filename\n", argv[0]); exit(1); } sock=socket(PF_INET, SOCK_STREAM, 0); memset(&client, 0, sizeof(client)); client.sin_family=AF_INET; client.sin_addr.s_addr=htonl(INADDR_ANY); client.sin_port=htons(PORT); fd=open(argv[1],O_CREAT|O_TRUNC|O_WRONLY,0); recv(sock, filesize, 128, 0); total = atol(filesize); printf("전송받을 크기 %ld\n",total); while((len = recv(sock,buf,BUFSIZE,0)) > 0) { str=write(fd,buf,len); if(str == BUFSIZE) { total-=(long)str; if(total <= 0) { printf("성공적으로 받기 완료\n"); str=0; break; } else { printf("성공 적으로 받아서 %ld 가 남았음\n",total); continue; } } else if(str < BUFSIZE) { total-=(long)str; if(total <=0) { printf("성공 완료\n"); break; } printf("비 성공적으로 %d 받았당 그러나 %ld 만큼 남았다\n",len,total); } else if(str==-1); { printf("전송 실패\n"); exit(0); } } close(sock); close(fd); return 0; }
여기선...
warning: passing arg 1 of `atol' from incompatible pointer type
컴파일은 돼는데...결과가 이상하네요...뭐가 잘못된건지..조언좀 부탁드립니다..
Forums:
int filesize[128]; -> char filesize[128];
sprintf나 atol은 char *을 입력으로 받습니다.
댓글 달기