Sams Teach Yourself C in 21 Days
Example int x; printf(“Printing only the even numbers from 1 to 10\n”); for( x = 1; x <= 10; x++ ) { if( x % 2 != 0 ) /* See ...
Advanced Program Control 315 13 20: else 21: goto location2; 22: 23: location0: 24: puts(“You entered 0.\n”); 25: goto end; 26: ...
It’s dangerous. The gotostatement might seem like an ideal solution for certain programming problems, but it’s easy to abuse. W ...
Advanced Program Control 317 13 you create an infinite loop. The condition that the whiletests is the constant 1 , which is alwa ...
LISTING13.4 menu.c. Using an infinite loop to implement a menu system 1: /* Demonstrates using an infinite loop to implement */ ...
Advanced Program Control 319 13 49: { 50: puts(“\nInvalid choice, try again.”); 51: delay(); 52: } 53: } 54: return 0; 55: } 56: ...
Invalid choice, try again. Enter 1 for task A. Enter 2 for task B. Enter 3 for task C. Enter 4 for task D. Enter 5 to exit progr ...
Advanced Program Control 321 13 TheswitchStatement ............................................................................. ...
11: 12: switch (reply) 13: { 14: case 1: 15: puts(“You entered 1.”); 16: case 2: 17: puts(“You entered 2.”); 18: case 3: 19: put ...
Advanced Program Control 323 13 8: 9: puts(“\nEnter a number between 1 and 5:”); 10: scanf(“%d”, &reply); 11: 12: switch (re ...
Enter a number between 1 and 5: 6 Out of range, try again. When you compile and run this version; you’ll see that it runs correc ...
Advanced Program Control 325 13 37: delay(); 38: break; 39: } 40: case 4: 41: { 42: puts(“\nExecuting task D.”); 43: delay(); 44 ...
Enter 1 for task A. Enter 2 for task B. Enter 3 for task C. Enter 4 for task D. Enter 5 to exit program. 1 Executing task A. Ent ...
Advanced Program Control 327 13 5: 6: int main( void ) 7: { 8: int reply; 9: 10: while (1) 11: { 12: puts(“\nEnter a value betwe ...
Enter a value between 1 and 10, 0 to exit: 6 You entered 6 or more. Enter a value between 1 and 10, 0 to exit: 0 This program ac ...
Advanced Program Control 329 13 default: printf( “I don’t have a case for %c”, letter ); } Example 2 switch( number ) { case 0: ...
Theexit()Function .................................................................................... Theexit()function termina ...
Advanced Program Control 331 13 The argument commandcan be either a string constant or a pointer to a string. For exam- ple, to ...
Input the desired system command, blank to exit dir *.bak Volume in drive E is BRAD_VOL_B Directory of E:\BOOK\LISTINGS LIST1414 ...
Advanced Program Control 333 13 Summary ........................................................................................ ...
«
13
14
15
16
17
18
19
20
21
22
»
Free download pdf