Application |
Example |
Notes |
A declaration statement creates a composite variable to store a group of chars. |
 |
- this is the same as regular
char arrays
- the size should be large enough to accommodate the longest possible string as the capacity
- the capacity should also ensure there's enough room for the null character:
\0
|
A single array element is used to access individual characters in the string. |
|
- this is the same as regular
char arrays
|
all array elements must be accessed one at a time |
 |
- this is the same as regular
char arrays except the loop should end at the null character \0 NOT the capacity
|
Strings are the only arrays that can be used directly with Formatted IO |
printf and scanf
code in your program file:

terminal while running the executable:
|
- the
%s conversion specifier allows you to send whole strings into the printf and scanf functions
- CAUTION! you cannot do this with any other type of array
- CAUTION!
printf only works for strings if there is a null character \0 in the array
- the
scanf function stops at the first blank space it sees
- CAUTION! it does not guarantee that a null character
\0 is stored in the array
|
fgets
code in your program file:

terminal while running the executable:
|
- the
fgets function stops at the first endline character \n
- it also stores that endline character
\n
- it does guarantee that a null character
\0 is stored in the array
|