The UNIX and Linux Forums  
Hello and Welcome from to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
simple scanf issue ? the_learner High Level Programming 4 04-11-2007 04:51 AM
problem with scanf mridula High Level Programming 4 12-23-2006 01:43 PM
scanf with strings... please help inkfish High Level Programming 1 05-25-2005 06:17 PM
raid 0+1 +oracle getting slow data reads. Optimus_P UNIX for Advanced & Expert Users 19 07-11-2003 07:50 PM
Scanf problem under LINUX... robotronic High Level Programming 4 04-19-2002 09:26 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-30-2005
DebianJ DebianJ is offline
Registered User
  
 

Join Date: May 2005
Posts: 52
scanf doesn´t reads spaces ???

hi all

i have a program in C (Unix Solaris 5.7) and i want to read a string from keyboard, but the "scanf" doesn´t reads spaces.
example:

....
char name[50];
....

printf("Enter your name: ");
scanf("%s",&name);
printf ("Your name is: %s", name);



and if i write Kevin Costner
the program only reads Kevin (that is what shows in the screen)

what can i do?
please help me...
thanks....

jona
  #2 (permalink)  
Old 05-30-2005
bhargav's Avatar
bhargav bhargav is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2004
Location: USA
Posts: 511
That is how ssanf works.

Use 'gets' instead.
  #3 (permalink)  
Old 05-31-2005
devesh devesh is offline
Registered User
  
 

Join Date: Mar 2005
Location: Mumbai, India
Posts: 12
give input in quotes"" for example "Kevin Costner"
  #4 (permalink)  
Old 05-31-2005
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
Quote:
bhargav: That is how ssanf works.
Use 'gets' instead.
Never use gets... use fgets instead.
  #5 (permalink)  
Old 05-31-2005
ramkumar_gr ramkumar_gr is offline
Registered User
  
 

Join Date: Nov 2003
Posts: 11
Use Scanset operators

You can use scanset operator [] for this.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:41 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0