>> SPEAKER: We'll call it a string.
It's just a sequence of characters.
Indeed, it's simply an array of characters.
And so even if we get a string from the user in the usual way with CS50's
GetString, we can then proceed to iterate over the chars in that string
one at a time as though that string is indeed an array.
Let's try this in code.
>> Include cs50.h.
Include stdio.h.
And let's also include string.h so that we have access
to StringLen function.
Let's now declare main as int main void.
And let's now proceed to get a string from the user.
Printf input.
Let's now declare a string calling it s, and call our friend GetString.
>> Let's now proceed to check, did the user indeed give me a string because
it turns out per GetString's own documentation, GetString could on
occasion return NULL, a special sentinel value that essentially
indicates that the user did not cooperate and somehow did
not provide a string.
So let's check for that with a condition.
>> IF s does not equal NULL, then we can assume that s is indeed a string, an
array of characters, and proceed to iterate over those characters.
FOR int i gets 0, let's also declare n as equal to the string length of s so
long as i is less than n, and on each iteration, let's increment i.
Within this loop THEN, let's call printf of %c backslash n and then plug
into this value s bracket i thereby printing one character at a time each
of the cars in s.
>> Let's now compile and run this program.
Make string.
./string My input will be "hello." And there we have it.
H-E-L-L-O, each char on its own line.