C Programming Absolute Beginner's Guide (3rd Edition)
Efficiency Considerations case statements don’t have to be arranged in any order. Even default doesn’t have to be the last case ...
printf("4. Quit\n"); // The top-menu choice and the switch statement that makes the // resulting // information appear are encas ...
} else if (choice2 == 3) { printf("\n\nUS Presidents in the 1980s:\n"); printf("1980: Jimmy Carter\n"); printf("1981-1988: Ronal ...
printf("1997: Titanic\n"); printf("1998: Shakespeare in Love\n"); printf("1999: American Beauty\n"); printf("\n\n\n"); break; } ...
printf("Return of the King\n"); printf("2004: Million Dollar Baby\n"); printf("2005: Crash\n"); printf("2006: The Departed\n"); ...
statements and nest for statements within other for statements, nesting switch statements is not a good idea, particularly when ...
18. Increasing Your Program’s Output (and Input) In This Chapter Using putchar() and getchar() Dealing with the newline conside ...
The name getchar() sounds like “get character,” and putchar() sounds like “put character.” Looks as though the designers of C kn ...
// getchar() is defined in stdio.h, but string.h is needed for the // strlen() function #include <stdio.h> #include <st ...
Although getchar() gets a single character, control isn’t returned to your program until the user presses Enter. The getchar() f ...
getchar() on lines by themselves. As long as you use these getchar()s for discarding Enter keypresses, you can ignore the compil ...
putch(lastInit); The next chapter explains more built-in functions, including two that quickly input and output strings as easil ...
19. Getting More from Your Strings In This Chapter Employing character-testing functions Checking whether the case is correct A ...
if (isdigit(inChar)) { printf("A number\n"); } Note Do you see why these are called character-testing functions? Both isalpha() ...
// File Chapter19ex1.c / This program asks a user for a username and a password. It tests whether their password has an uppercas ...
if ((hasDigit) && (hasUpper) && (hasLower)) { printf("\n\nExcellent work, %s,\n", user); printf("Your password h ...
The following program segment prints yes or no, depending on the user’s input. Without the toupper() function, you need an extra ...
The puts() and gets() functions provide an easy way to print and get strings. Their descriptions are in stdio.h, so you don’t ha ...
Here is the output from a sample run of this program: Click here to view code image What town do you live in? Gas City What stat ...
puts() automatically adds a newline to the end of strings. ...
«
3
4
5
6
7
8
9
10
11
12
»
Free download pdf