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

Posted on 2004-10-04
Last Modified: 2012-06-21
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;

      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);

I get the following errors:
--------------------Configuration: Program 3 - Win32 Debug--------------------
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?

Question by:bjw5d6
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
LVL 19

Accepted Solution

mrwad99 earned 500 total points
ID: 12216478
>> #define WSVERS          MAKEWORD(2, 0);


>>    if(WSAStartup(WSVERS, &wsadata))

expands to

if (WSAStartup(MAKEWORD(2, 0);, &wsadata))

Lose the ; from the preprocessor directive :)
LVL 19

Expert Comment

ID: 12216487
...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.

Author Comment

ID: 12231769
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!
LVL 19

Expert Comment

ID: 12235068
Glad to help :)

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question