🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

variable not initialized problem.

Started by
3 comments, last by kalldrex 23 years, 4 months ago
heh i know i''m probably annoying you guys but I really need help lol. Then again what''s this forum for? anyways here''s my code:
  
#include <stdio.h>
#include <winsock2.h>
#include <iostream.h>
int main(int argc, char* argv[])
{
	cout <<"The Nonamed Game Server Version 0.1a\nBy:Matthew Shapiro\n\n";
	sockaddr_in me;
	WSADATA wsaData;
	SOCKET s;
	char *namebuf;
	char *passbuf;
	sizeof(namebuf)[25];
	sizeof(passbuf)[25];
	char username;
	char password;
	int nRet = 0;
	if((nRet = WSAStartup(MAKEWORD(2,0), &wsaData)))
	{
		switch(nRet)
		{
		case WSASYSNOTREADY:
			printf("WSASYSNOTREADY\n");
		case WSAVERNOTSUPPORTED:
			printf("WSAVERNOTSUPPORTED\n");
		case WSAEINPROGRESS:
			printf("WSAEINPROGRESS\n");
		case WSAEPROCLIM:
			printf("WSAEPROCLIM\n");
		case WSAEFAULT:
			printf("WSAEFAULT\n");
	};		return 1;
	}
	s = socket(AF_INET, SOCK_DGRAM, 0);
    if (s == INVALID_SOCKET)
    {
        printf("socket() failed; %d\n", WSAGetLastError());
        return 1;
    }
	me.sin_family = AF_INET;
	me.sin_port = htons(5151);
	me.sin_addr.s_addr = htonl(INADDR_ANY);
	cout <<"Testing\n";
	if (bind(s, (SOCKADDR *)&me, sizeof(me)) == SOCKET_ERROR)
	{
		cout <<"bind() failed: ";WSAGetLastError();
		return 1;
}
	int err = recv(s,namebuf,sizeof(namebuf),0);
	if (err==0 || err==INVALID_SOCKET)
	{
		cout <<"Couldn''t recieve username: "<<WSAGetLastError()<<''\n'';
		return 1;
}
	username;
	err = recv(s,passbuf,sizeof(passbuf),0);
	if (err==0 || err==INVALID_SOCKET)
	{
		cout <<"Couldn''t recieve password: "<<WSAGetLastError()<<''\n'';
		return 1;
}
	cout <<"everything works right now\n";
password;
return 1;
}
  
and here are the warnings it''s producing that seem to make it give me the 10014 error: [qoute] E:\Programming\Test\grr.cpp(48) : warning C4700: local variable ''namebuf'' used without having been initialized E:\Programming\Test\grr.cpp(55) : warning C4700: local variable ''passbuf'' used without having been initialized Linking... grr.exe - 0 error(s), 2 warning(s) heh any ideas on how to make this work? (btw my computer seems really screwed up and for some reason doing things like "char *namebuff=new char[25]; hangs the program at startup so that won''t work. Any ideas?
ALL YOUR BASE ARE BELONG TO US!!!!
Advertisement
Try:

  char namebuf[25];char passbuf[25];  
Matt Slot / Bitwise Operator / Ambrosia Software, Inc.
nope that also makes the whole program freeze on startup!
ALL YOUR BASE ARE BELONG TO US!!!!
      // Change this    //    char *namebuf;	    char *passbuf;	    sizeof(namebuf)[25]; // Note : this is just crap I think.    sizeof(passbuf)[25]; // It creates arrays of 25 pointers to chars, not a array of 25 chars    // To this    //    const int MAX_LENGTH = 25;    char namebuf[MAX_LENGTH];	    char passbuf[MAX_LENGTH];	    // And this    //    recv(s,namebuf,sizeof(namebuf),0);    // To this    //    recv(s,namebuf,MAX_LENGTH,0);    // Change it the same way :    //    recv(s,passbuf,sizeof(passbuf),0);    



Edited by - Prosper/LOADED on February 21, 2001 6:34:34 PM
You could just use:

char *namebuff = new char(25);
char *passbuff = new char(25);

When done with the program, don''t forget:

delete [] namebuff;
delete [] passbuff;

This topic is closed to new replies.

Advertisement