The UNIX and Linux Forums  
Hello and Welcome from United States 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
Problem in For Loop The Observer Shell Programming and Scripting 2 05-28-2008 02:43 AM
for loop problem namishtiwari Shell Programming and Scripting 5 01-25-2008 12:58 PM
loop problem maskot Shell Programming and Scripting 1 05-25-2007 04:10 AM
Problem with for loop/sed ? chiru_h Shell Programming and Scripting 2 08-27-2006 11:55 AM
loop Problem dhananjaysk Shell Programming and Scripting 3 03-31-2006 01:05 PM

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

Join Date: Sep 2005
Posts: 20
problem with while loop

hi all,
i have written the following code:
while(proceed !='Y' && proceed!='N' && proceed!='y' && proceed!='n')
{

printf("\nPress \n\t 'Y' or 'y' to continue \n\t 'N' or 'n' to cancel:");
scanf("%c",&proceed);
}

the output i am gettin is:

Press
'Y' to continue
'N' to cancel
: a
Press
'Y' to continue
'N' to cancel
: (not allowing me to enter the value here and directly printing once more.)
Press
'Y' to continue
'N' to cancel
: b
Press
'Y' to continue
'N' to cancel
:
Press
'Y' to continue
'N' to cancel
:


why is this happening can nyone help me with this??

thanx
  #2 (permalink)  
Old 12-11-2005
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
You did not just type an "a". You typed an "a" followed by a newline character. Try typing "unix" and watch what happens. This is one of several reason why I do not like scanf. What is worse here, you do not need scanf for anything. I would define a character array called inputline to be 80 characters. Then I would use fgets (never use gets) to read a line of input. Finally just "proceed=inputline[0]" to get the first character and discard the rest of the line.
Sponsored Links
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 08:39 PM.


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