TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: Keith Fowler
from: Paul Edwards
date: 1996-08-24 12:54:28
subject: Libraries

KF> While I'm here though, could you please tell me why this doesn't work
KF> porperly:
KF> char name[30];
KF> printf("Please Enter Name: ");
KF> scanf("%s",name);

KF> when this inputs the string, if I have a space in bewteen something
KF> (for example "Keith Fowler") it only puts
"Keith" in the name[30], then if 

That's what scanf does - stop at the first space.

KF> I do another scanf it then puts "Fowler" starigh into that
string....

KF> Am I using a wrong command??, or am I using this one wrong?, if ya
KF> could help me out it would be great!.. Thanks..bye

If you want to read in a whole line, I suggest:

fgets(name, sizeof name, stdin);

You will then need to strip the '\n'.

You could use:

gets(name);

which strips the '\n' for you, but that has no max-length protection. BFN.  Paul.
@EOT:

---
* Origin: X (3:711/934.9)

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.