Click here to Skip to main content
15,892,839 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: pliz help me with input validation Pin
Christian Graus7-Apr-05 15:14
protectorChristian Graus7-Apr-05 15:14 
GeneralRe: pliz help me with input validation Pin
Anonymous7-Apr-05 15:35
Anonymous7-Apr-05 15:35 
GeneralRe: pliz help me with input validation Pin
Christian Graus7-Apr-05 15:39
protectorChristian Graus7-Apr-05 15:39 
GeneralRe: pliz help me with input validation Pin
mpapeo7-Apr-05 15:50
mpapeo7-Apr-05 15:50 
GeneralRe: pliz help me with input validation Pin
Christian Graus7-Apr-05 15:52
protectorChristian Graus7-Apr-05 15:52 
GeneralRe: pliz help me with input validation Pin
mpapeo8-Apr-05 1:48
mpapeo8-Apr-05 1:48 
GeneralRe: pliz help me with input validation Pin
David Crow8-Apr-05 5:29
David Crow8-Apr-05 5:29 
GeneralRe: pliz help me with input validation Pin
LighthouseJ7-Apr-05 15:48
LighthouseJ7-Apr-05 15:48 
Why comment out the scanf?

try this ...
<br />
int choice;<br />
while (true) {<br />
printf ("\n");<br />
printf ("*****************************************\n");<br />
printf ("*\t\t\t\t\t*\n*\tPROCESS CREATION \t\t*\n");<br />
printf ("=========================================");<br />
printf ("\n=\t 1: Create a process \t\t=");<br />
printf ("\n=\t 2: Suspend the process\t\t=");<br />
printf ("\n=\t 3: Resume process \t=");<br />
printf ("\n=\t 4: Shutdown the process \t=");<br />
printf ("\n=========================================\n");<br />
printf ("\n");<br />
printf ("\nEnter choice (1-4): ");<br />
<br />
scanf("%u", &choice);<br />
<br />
switch (choice) {<br />
case 1:<br />
case 2:<br />
case 3:<br />
case 4: return choice; break;<br />
default: printf("\nPlese enter numeric digits only (1-4)\n"); break;<br />
}<br />
}<br />


Now the while(true) { } loop is used, it should be used sparingly. That loop will keep iterating through the menu indefinitely. The only way to get out is to choose one of the valid options. The switch will catch options 1 through 4 and return them, anything else will show the error. The switch-case statement is very useful in this case because you can run code for each option and handle all other cases. If you choose say option 2, it'll enter at case 2 but then keep going through case 3 and then it will reach case 4, return the number 2 (stored in choice) and then break; (it's really unreachable code because the function will end at the return statement.
GeneralRe: pliz help me with input validation Pin
mpapeo7-Apr-05 15:59
mpapeo7-Apr-05 15:59 
GeneralRe: pliz help me with input validation Pin
mpapeo7-Apr-05 16:21
mpapeo7-Apr-05 16:21 
Generalemulating commands in c++ Pin
Jeb997-Apr-05 14:32
Jeb997-Apr-05 14:32 
GeneralRe: emulating commands in c++ Pin
Christian Graus7-Apr-05 15:14
protectorChristian Graus7-Apr-05 15:14 
QuestionWhere to download a crystal report tool from? Pin
awasthy7-Apr-05 13:52
awasthy7-Apr-05 13:52 
AnswerRe: Where to download a crystal report tool from? Pin
liquid_8-Apr-05 7:13
liquid_8-Apr-05 7:13 
GeneralUnhandled Exception. Pin
blinkered7-Apr-05 11:28
blinkered7-Apr-05 11:28 
GeneralRe: Unhandled Exception. Pin
Shaileshhex22-Jul-08 1:50
Shaileshhex22-Jul-08 1:50 
Generalflat toolbar in WinXP Pin
BaShOr7-Apr-05 10:27
BaShOr7-Apr-05 10:27 
GeneralRe: flat toolbar in WinXP Pin
Mark Salsbery15-Nov-06 11:32
Mark Salsbery15-Nov-06 11:32 
GeneralHelp with a school project Pin
diegomiami7-Apr-05 10:02
diegomiami7-Apr-05 10:02 
GeneralRe: Help with a school project Pin
Ravi Bhavnani7-Apr-05 11:33
professionalRavi Bhavnani7-Apr-05 11:33 
GeneralRe: Help with a school project Pin
diegomiami7-Apr-05 11:51
diegomiami7-Apr-05 11:51 
GeneralRe: Help with a school project Pin
Ravi Bhavnani7-Apr-05 11:54
professionalRavi Bhavnani7-Apr-05 11:54 
GeneralRe: Help with a school project Pin
David Crow7-Apr-05 16:25
David Crow7-Apr-05 16:25 
GeneralDisableTaskMgr for USER GROUP not with gpedit Pin
nadzzz7-Apr-05 9:26
nadzzz7-Apr-05 9:26 
GeneralRe: DisableTaskMgr for USER GROUP not with gpedit Pin
ThatsAlok7-Apr-05 18:24
ThatsAlok7-Apr-05 18:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.