Follow us on Twitter!
Never in the field of human conflict was so much owed by so many to so few. - Winston Churchill
Friday, April 18, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 24
Guests Online: 23
Members Online: 1

Registered Members: 82828
Newest Member: uberscon
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

C string not long enough


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 22-06-06 10:01
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



Author

RE: RE: C string not long enough

Alienz
Member

Your avatar

Posts: 2
Location: Slovakia
Joined: 14.06.06
Rank:
Guest
Posted on 22-06-06 10:10
try fgets(message,255,stdin); or gets(message);
Author

RE: C string not long enough


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 22-06-06 10:28
no luck, that didnt work either..


Author

RE: RE:

Alienz
Member

Your avatar

Posts: 2
Location: Slovakia
Joined: 14.06.06
Rank:
Guest
Posted on 22-06-06 10:54
So you are doing something wrong... Scanf(%s) read chars until first white character but gets read string until you write new line char - '&*92;n'. You can read this: http://www.unet.univie.ac.at/aix/libs/basetrf1/gets.htm
Author

RE: C string not long enough


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 06-07-06 16:25
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..

Code

#include <stdio.h>

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

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

   return 0;
}