Page 1 of 1
Why does this crash?!
Posted: Mon Oct 04, 2004 9:20 pm
by Red Squirrel
Code: Select all
char username[16];
memset(username,0,16);
int position=0;
char chardata;
strcpy(message,"
Login:");
send(theClient,message,strlen(message),0);
while((chardata!='
')&&(position<16))
{
recv(theClient,&chardata,1,0);
username[position]=chardata;
send(theClient,&username[position],1,0);
position++;
}
What did I do wrong? I'm confused. It just crashes with a bunch of weird numbers and invalid addresses, basically something worse then the illegal operation. But it makes no sense the code is as simple as it gets.
Archived topic from Anythingforums, old topic ID:1125, old post ID:14166
Why does this crash?!
Posted: Fri Oct 08, 2004 1:47 am
by megaspaz
put in stubs to isolate which line is crashing. stubs are basically debugging output (in c++, use cout in various places).
where is message defined at? it looks like you're just using a prompt, so why are you using strcopy for? have the client handle user prompts like logging in prompts and use cout instead of strcopy.
Archived topic from Anythingforums, old topic ID:1125, old post ID:14539
Why does this crash?!
Posted: Fri Oct 08, 2004 1:31 pm
by Red Squirrel
I got it sorted out, I did not know I couldnot use a char *. I figured char * was like a php variable (unlimited) but it turns out it just uses whatever memory is available, including memory already in use, so it crashed when it got to a memory address that was in use.
strcpy is just so I don't have to count all the chars for each string insertion in the send command. Once I get this simple program working I'll tweak it better and take the time to count all the chars. (the send command requires to put the number)
Archived topic from Anythingforums, old topic ID:1125, old post ID:14577