Follow us on Twitter!
Never in the field of human conflict was so much owed by so many to so few. - Winston Churchill
Sunday, April 20, 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: 32
Guests Online: 27
Members Online: 5

Registered Members: 82848
Newest Member: aIjundi
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

Basic input output (C++)


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 30-03-09 04:10
Hey I am having a bit of trouble with some C++ input.
I have a string which will store an address, however when it encounters a space in the input it will randomize the rest of the inputs.
So say we have a string
Code

string adrs;
cout << "Input your ADDRESS: ";
cin >> adrs;
cout << "Your address is: " << adrs << endl;





If the string adrs becomes
Code
444 penny lane



then the spaces would make the script not function, and crash. How can I handle the input of spaces?

Well night, have a good one guys.
Author

RE: Basic input output (C++)

spyware
Member



Posts: 4192
Location: The Netherlands
Joined: 14.04.07
Rank:
God
Warn Level: 90
Posted on 30-03-09 04:17
Do you realize the answer is one search away?



img507.imageshack.us/img507/3580/spynewsig3il1.png
"The chowner of property." - Zeph
[small]
Widespread intellectual and moral docility may be convenient for leaders in the short term,
but it is suicidal for nations in the long term.
- Carl Sagan
“Since the grid is inescapable, what were the earlier lasers about? Does the corridor have a sense of humor?” - Ebert
[/s

Edited by spyware on 30-03-09 04:19
http://bitsofspy.net
Author

RE: Basic input output (C++)

ynori7
Member



Posts: 1486
Location: #valhalla
Joined: 08.10.07
Rank:
God
Posted on 30-03-09 05:42
getline(cin, adrs);

That grabs the whole line rather than just the first word.
You could also write it as:
cin.getline (adrs ,256);
That takes the first 256 characters entered.

http://www.cplusp. . .tline.html



halls-of-valhalla.org/images/affiliateLogo.png voodoorage.halls-of-valhalla.org/images/smallLogo.png
i537.photobucket.com/albums/ff338/ynori77/archenemysig1.jpg
ynori7 http://halls-of-valhalla.org
Author

RE: STDIO.H


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 30-03-09 07:02
I would have preferred using gets...quite easy to use and you don't even have to change it if you want to convert your program to C.
You will have to include another header file(stdio.h)
syntax:
gets(stringname);

Gets can get the spaces too.
another good function in here is
puts(stringname);

it automatically adds a newline at the end.Of course if u want to stick with iostream.h...

cin.getline(stringname,no.ofcharecters);




Edited by on 30-03-09 07:03
Author

RE: Basic input output (C++)

ynori7
Member



Posts: 1486
Location: #valhalla
Joined: 08.10.07
Rank:
God
Posted on 30-03-09 14:30
onejerlo wrote:
I would have preferred using gets...quite easy to use

Never use gets(). It's not a safe function. It's easy for someone to exploit with a buffer overflow. I have a simple example in the code bank in C.
http://www.hellbo. . .1217_.html

EDIT: If you want to go with stdio, use scanf().


halls-of-valhalla.org/images/affiliateLogo.png voodoorage.halls-of-valhalla.org/images/smallLogo.png
i537.photobucket.com/albums/ff338/ynori77/archenemysig1.jpg


Edited by ynori7 on 30-03-09 14:32
ynori7 http://halls-of-valhalla.org
Author

RE: @ynori7


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 30-03-09 15:37
Yeah...good point..my bad..but scanf cant input spaces directly either...

@chronicburst
I guess u can use cin.getline(stringname,no.ofcharecters)......
or u can code up your own header file and make a function of your own and use it.(dont know if that comes under basic or not)


Author

RE: Basic input output (C++)

ynori7
Member



Posts: 1486
Location: #valhalla
Joined: 08.10.07
Rank:
God
Posted on 30-03-09 15:54
onejerlo wrote:
but scanf cant input spaces directly either...

True. If you need spaces, you can use fgets(). That's a buffer safe version of gets().


halls-of-valhalla.org/images/affiliateLogo.png voodoorage.halls-of-valhalla.org/images/smallLogo.png
i537.photobucket.com/albums/ff338/ynori77/archenemysig1.jpg
ynori7 http://halls-of-valhalla.org
Author

RE: Basic input output (C++)


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 30-03-09 21:46
Awesome,
cin.getline ()
is working great.
Thank you for the numerous replies.