Where is my error in this code?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  #include <stdio.h>
  #include <stdlib.h>
  #include <stdint.h>

  #include <winsock2.h>

  int main(){
     #include <stdio.h>
  #include <stdlib.h>
  #include <stdint.h>

  #include <winsock2.h>

  int main(){
   typedef struct addrinfo * hints;
   typedef struct addrinfo *  res;
    int       status;

    WSADATA   wsadata;
    int statuswsadata;
    if((statuswsadata=WSAStartup(MAKEWORD(2,2),&wsadata))!=0){
      printf("WSAStartup failed: %d\n",statuswsadata);
    }

    hints->ai_family   =AF_INET;

    status=getaddrinfo("173.194.70.105",0,0,&res);

    {
      char host[512],port[128];

      status=getnameinfo(res->ai_addr,res->ai_addrlen,host,512,0,0,0);

      printf("Host: %s",host);

      freeaddrinfo(res);
    }
  }


Here is error output:
1
2
3
4
syntax error before '->' token 
syntax error before "res"
syntax error before "res"  
syntax error before "res" 
You defined main two times

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

#include <winsock2.h>

int main(){
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

#include <winsock2.h>

int main(){
Yes, there were two main's in your code. It should look more like this.

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

#include <winsock2.h>


int main()
{
typedef struct addrinfo * hints;
typedef struct addrinfo * res;
int status;

WSADATA wsadata;
int statuswsadata;
if((statuswsadata=WSAStartup(MAKEWORD(2,2),&wsadata))!=0)
{
printf("WSAStartup failed: %d\n",statuswsadata);
}

hints->ai_family =AF_INET;

status=getaddrinfo("173.194.70.105",0,0,&res);


char host[512],port[128];

status=getnameinfo(res->ai_addr,res->ai_addrlen,host,512,0,0,0);

printf("Host: %s",host);

freeaddrinfo(res);

}
Last edited on
Topic archived. No new replies allowed.