Quantcast
Channel: noob help with switch/case
Viewing all articles
Browse latest Browse all 11

noob help with switch/case

$
0
0
well, the first thing you did was read the value:
   char keys = 'l';
   while( keys != 'x' ) {
...so I suggest you give it an initial value that is anything but 'x' to make sure you get into your loop.  Leaving it uninitialized is a bad idea.


Alternatively, put your exit condition in the loop.  And check your return values!

for(;;) {
   char key;
   int numberOfFieldsScanned = scanf("%c", &key );
   if( numberOfFieldsScanned != 1 || key == 'x' ) break;
   switch( key ) {
   /* blah blah blah */
   }
}










Viewing all articles
Browse latest Browse all 11

Latest Images

Trending Articles





Latest Images