Learn How to Program in Cby
|
Type this source code in your editor and save it as char.c then compile it, link it, and run it. Depending on whether your computer uses the ASCII standard, you may get different answers to this question. In this example, we used %d to convert your letter into a number. Actually, we simply used the integer (digit) format to display your letter. StringWhen you need to store more than one letter in memory, use a string. Strings can hold letters, words, phrases, sentences. For this type of variable, we must specify how many characters are in the string, plus one extra. The extra character is the \0 or NULL, which the computer uses to mark the end of the string. For example, if we expect someone's first name to be less than 10 letters, we write: char first[10]. Then we use the format specifier %s to print the value of the first name, as in this example:
Save this as school.c then compile it, link it, and run it. Multiple StringsNow, if we ask for the first and last names, we should increase the number of characters in the last name (since some of us have extremely long last names!):
Type this source code in your editor and save it as string.c then compile it, link it, and run it. If one of your names is longer than the number of characters declared, then go back and change the numbers in your declaration lines. Remember to give one extra character for the \0 or NULL. Strings with SpacesIf you initialize a string that has spaces in it, like Integrated Development Environment, leave the character number blank, like this: [ ]. Type the variable value in double quotes, like this: " ".
Type this source code in your editor and save it as editor.c then compile it, link it, and run it. |
||||||||||
|
Copyright © 2001 Kristin Switala |
|||||||||||