Welcome to HBH! If you had an account on hellboundhacker.org you will need to reset your password using the Lost Password system before you will be able to login.

C string not long enough


ghost's Avatar
0 0

Hmmm, im writing an infinite net send program in c, and you can enter your own message. I use

scanf("%s",message);

to get the string, then i use

printf("MESSAGE %s SET",message);

to show the message back to me. but if i enter "hello world" (with or without quotes) the printf() returns

MESSAGE hello SET

Any one know how you fix this, or have a link to a site where it has info on this sort of stuff?

thanks, Zalifer


Alienz's Avatar
Member
0 0

try fgets(message,255,stdin); or gets(message);


ghost's Avatar
0 0

no luck, that didnt work either..


ghost's Avatar
0 0

I have no idea how you are screwing this up, but I typed up some quick code to show you what yours should look like..

#include <stdio.h>

int main(int argc, char *argv[])
{
	char message[20];

	gets(message);
	printf("MESSAGE %s SET",message);

	return 0;
}