Solved

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

Posted on 2004-10-04
4
547 Views
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;

      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?

0
Comment
Question by:bjw5d6
  • 3
4 Comments
 
LVL 19

Accepted Solution

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

with

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

expands to

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

Lose the ; from the preprocessor directive :)
0
 
LVL 19

Expert Comment

by:mrwad99
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.
0
 

Author Comment

by:bjw5d6
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!
0
 
LVL 19

Expert Comment

by:mrwad99
ID: 12235068
Glad to help :)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

820 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