Link to home
Start Free TrialLog in
Avatar of bjw5d6
bjw5d6

asked on

What is wrong with my code: WSAStartup errors...

I included wsock32.lib into the settings->link->object
and when I compile the following: (partial code shown)

#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <winsock.h>

using namespace std;

void errexit(const char *, ...);
void UDPecho_cnls(const char *host, const char *service);

#define LINELEN            128
#define WSVERS            MAKEWORD(2, 0);


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

      char      *host = argv[1], *service = argv[2];
      WSADATA      wsadata;

      if(argc!=3)
      {
      cout<<"Command line does not contain the        

                                correct "<<endl;
            cout<<" number of arguments."<<endl;
      }

      if(WSAStartup(WSVERS, &wsadata))
            errexit("WSAStartup failed\n");

      UDPecho_cnls(host, service);
      WSACleanup();
      exit(0);
}


I get the following errors:
--------------------Configuration: Program 3 - Win32 Debug--------------------
Compiling...
Program 3.cpp
C:\CS423P3\Program 3.cpp(28) : error C2143: syntax error : missing ')' before ';'
C:\CS423P3\Program 3.cpp(28) : error C2660: 'WSAStartup' : function does not take 1 parameters
C:\CS423P3\Program 3.cpp(28) : error C2143: syntax error : missing ')' before ';'
C:\CS423P3\Program 3.cpp(28) : warning C4390: ';' : empty controlled statement found; is this the intent?
C:\CS423P3\Program 3.cpp(28) : error C2143: syntax error : missing ';' before ','
C:\CS423P3\Program 3.cpp(28) : error C2059: syntax error : ')'
C:\CS423P3\Program 3.cpp(28) : error C2059: syntax error : ')'
Error executing cl.exe.

Program 3.obj - 6 error(s), 1 warning(s)


All the errors relate to the
      if(WSAStartup(WSVERS, &wsadata))
            errexit("WSAStartup failed\n");
code.  What is wrong?  Am I leaving a library out?

ASKER CERTIFIED SOLUTION
Avatar of mrwad99
mrwad99
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
...You need to remember that #define'd symbols like this are replaced *exactly* as you define them.  So the problem in this case was simply you adding the unncecessary ; after your WSVERS definition.
Avatar of bjw5d6
bjw5d6

ASKER

OH!  Thanks so much!  I already turned my code in... I ended up changing the
#define to Word (or something like that) and then it worked.  I didn't know why it didn't work w/ #define, because I saw that my instructor used #define in his notes... I get it now! No ; !!!  Thanks for your help!
Glad to help :)