0

I have this code which is working fine:

#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
    struct in_addr addr;

    if (argc != 2) {
        fprintf(stderr, "%s <dotted-address>\n", argv[0]);
        exit(EXIT_FAILURE);
    }

    if (inet_aton(argv[1], &addr) == 0) {
        perror("inet_aton");
        exit(EXIT_FAILURE);
    }

    printf("%s\n", inet_ntoa(addr));
    exit(EXIT_SUCCESS);
}

What I want to achieve is print the value of inet_aton() function. The description of function says that it returns a number, but when I try to print it, it says "cannot covert from address structure to decimal".

LogicStuff
  • 19,397
  • 6
  • 54
  • 74
sheldon cooper
  • 455
  • 2
  • 8
  • 22

1 Answers1

0

Using this instead of your last printf worked for me:

printf("%d\n", addr.s_addr);
brenns10
  • 3,109
  • 3
  • 22
  • 24
  • If you just do `printf("%d\n", addr);`, you'll get a compiler warning (since this is bad form), but it will still work. – brenns10 Apr 05 '15 at 15:28