warning: passing arg 1 of `inet_addr' makes pointer from integer without a cast


 
Thread Tools Search this Thread
Top Forums Programming warning: passing arg 1 of `inet_addr' makes pointer from integer without a cast
# 1  
Old 12-11-2009
Question warning: passing arg 1 of `inet_addr' makes pointer from integer without a cast

I use solaris10,following is tcp client code:
Code:
#include "cliserv.h"
int main(int argc,char argv[]){
  struct sockaddr_in serv;
  char request[REQUEST],reply[REPLY];
  int sockfd,n;
  if(argc!=2)
    err_quit("usage: tcpclient <IP address of server>");
  if((sockfd=socket(PF_INET,SOCK_STREAM,0))<0)
    err_sys("socket error");
  memset(&serv,0,sizeof(serv));
  serv.sin_family=AF_INET;
  serv.sin_addr.s_addr=inet_addr(argv[1]);
  serv.sin_port=htons(TCP_SERV_PORT);
  if(connect(sockfd,(SA)&serv,sizeof(serv))<0)
    err_sys("connect error");
  if(write(sockfd,request,REQUEST)!=REQUEST)
    err_sys("write error");
  if(shutdown(sockfd,1)<0)
    err_sys("shutdown error");
  exit(0);
}

when I compile it,it raise following warning:
$gcc -lsocket -lnsl tcpclient.c -o tcpclient
tcpclient.c: In function `main':
tcpclient.c:12: warning: passing arg 1 of `inet_addr' makes pointer from integer without a cast

When I execute it,it raise following error:
$tcpserver &
$tcpclient 127.0.0.1
Segmentation Fault (core dumped)

How to correct above error? How to modify "tcpclient.c:12: warning: passing arg 1 of `inet_addr' makes pointer from integer without a cast"?

Thanks
# 2  
Old 12-23-2009
Hi,

You've defined argv as an array of characters, rather than an array of character arrays (i.e. strings). Change your 'main' function definition to this (note the asterisk):

int main(int argc,char *argv[]){

Or, my prefered way of writing it:

int main(int argc,char **argv){

Kind regards,

Andy Barry

Last edited by vbe; 12-26-2009 at 10:09 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Warning: pointer type mismatch

Hi all, I'm new programming in C, so I had the next message in my code: Dual.c:88:20: warning: pointer type mismatch in conditional expression : &clientSa.sin6.sin6.sin6_addr, Any help would be great #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include... (1 Reply)
Discussion started by: godna
1 Replies

2. Shell Programming and Scripting

Passing argument 1 of 'scanf' makes po

$ cc Array.c Array.c: In function ‘main’: Array.c:23: warning: passing argument 1 of ‘scanf’ makes po Array.c:25: error: expected expression before ‘return’ Array.c:29: error: expected expression before ‘return’ Array.c: At top level: Array.c:44: error: expected ‘)’ before ‘&’ token... (8 Replies)
Discussion started by: sgradywhite
8 Replies

3. UNIX for Dummies Questions & Answers

Counting vowels in string. "Comparison pointer-integer".

I'm trying to write a programme which scans strings to find how many vowels they contain. I get an error saying that I'm trying to compare a pointer and an integer inif(*v == scanme){. How can I overcome this ? Also, the programme seems to scan only the first word of a string e.g.: if I type "abc... (1 Reply)
Discussion started by: fakuse
1 Replies

4. Programming

warning: comparison between pointer and integer

Hi guys :D I am still playing with my C handbook and yes, as you can see I have small problem as always :cool: I wrote a C code #include <stdio.h> #define MESSAGE 100 int main(void) { char input_mes - Pastebin.com And when I try to compile it I get following errors from gcc ... (1 Reply)
Discussion started by: solaris_user
1 Replies

5. Shell Programming and Scripting

passing integer in getopts

Hi, I'm writing a shell script where I need to parse the command line arguments using "getopts" command. While using getopts I need to know how to pass numeral values to getopts. For example: while getopts ":h" Option do case $Option in h ) display_help;; ... (5 Replies)
Discussion started by: arun_maffy
5 Replies

6. Programming

warning: int format,pid_t arg (arg 2)

I try following code under Solaris10,like follows: int glob = 6; int main(void) { int var; pid_t pid; var = 88; printf("before vfork\n"); if ((pid = vfork()) < 0) { err_sys("vfork error"); } else if (pid == 0) { glob++; var++; _exit(0); } ... (1 Reply)
Discussion started by: konvalo
1 Replies

7. Programming

`strcat' makes pointer from integer without a cast

A question to ask. seq1 = "eeeeeeeeeeeeeeeeee"; seq2 = "dddddddddddddddddddd"; char a = '*'; strcat(*seq2, &a); strcat(*seq1, seq2); compilation warning: passing arg 1 of `strcat' makes pointer from integer without a cast thanks (4 Replies)
Discussion started by: cdbug
4 Replies

8. Programming

comparison between pointer and integer

I received a warning when I tried to compile my program that said: warning: comparison between pointer and integer Could you please explain to me what this means, and in what ways I could possibly fix this? Thanks for your help! (2 Replies)
Discussion started by: sjung10
2 Replies

9. Shell Programming and Scripting

cat behavior when passing http prams as arg

Hello all im newbie in unix , as my experiences i passed to the cat utility http prams as args i got : cat http://localhost:8000/test.php? szAddress=&szNationalId=&szFirstName=&szLastName=&undefined=undefined&iTargetModule=0&bFullScreen= and the result is : 2540 3016 2356 2552 ... (0 Replies)
Discussion started by: umen
0 Replies

10. Programming

Will we get SEGV if we try to “delete []” un-initialized integer pointer variable.

I have a class with an integer pointer, which I have not initialized to NULL in the constructor. For example: class myclass { private: char * name; int *site; } myclass:: myclass(....) : name(NULL) { ..... } other member function “delete “ the variable before... (2 Replies)
Discussion started by: sureshreddi_ps
2 Replies
Login or Register to Ask a Question