Thread: Method are not declared

  1. #1
    Registered User
    Join Date
    Feb 2019
    Posts
    69

    Method are not declared

    Hey,

    my compilers cries about the following code:

    Code:
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netdb.h>
    #include <stdio.h>
    #include<string.h>
    
    
    
    
    int main(int argc,char **argv)
    {
        int sockfd,n;
        char sendline[100];
        char recvline[100];
        struct sockaddr_in servaddr;
        
        
        sockfd=socket(AF_INET,SOCK_STREAM,0);
        bzero(&servaddr,sizeof servaddr);
        
        servaddr.sin_family=AF_INET;
        servaddr.sin_port=htons(22000);
        
        inet_pton(AF_INET,"127.0.0.1",&(servaddr.sin_addr));
        
        connect(sockfd,(struct sockaddr *)&servaddr,sizeof(servaddr));
        
        while(1)
        {
            bzero( sendline, 100);
            bzero( recvline, 100);
            fgets(sendline,100,stdin); /*stdin = 0 , for standard input */
            
            write(sockfd,sendline,strlen(sendline)+1);
            read(sockfd,recvline,100);
            printf("%s",recvline);
        }
        
    }
    The methods write(),read(),inet_pton(): Implicit declaration of function 'inet_pton' is invalid in C99

    So i try to declare them (but wondered, because they should be declared?). Either I got the signature wrong or he does not care about the declaration...

  2. #2
    Registered User
    Join Date
    Feb 2019
    Posts
    1,078
    inet_pton(), declared in arpa/inet.h;
    read() and write(), declared in unistd.h;

    Assuming you are using Linux, if your distro has the manpages-dev package, install it and use man...

  3. #3
    Registered User
    Join Date
    Feb 2019
    Posts
    69
    No I actually use MacOS. Thing is it works with eclipse, but not with Xcode (Did not know this when I created the post).
    Can I update C99 to C11 in xCode?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 09-20-2018, 12:55 AM
  2. Replies: 0
    Last Post: 09-20-2018, 12:55 AM
  3. Method Calls another Method
    By FourAngels in forum C++ Programming
    Replies: 2
    Last Post: 09-07-2015, 12:08 PM
  4. Encrypt method (from decrypt method)
    By mmmmmm in forum C# Programming
    Replies: 3
    Last Post: 09-19-2009, 10:35 AM
  5. Replies: 3
    Last Post: 10-12-2006, 06:58 AM

Tags for this Thread