Your main error is using ||
insted of &&
in printWord
. With ||
the condition will always be true since the character will always not be either space or the null character.
Some other points:
It's more portable for main
to return an int
(and have a return 0;
at the end).
Use of gets
is discouraged as it allows buffer overruns. fgets
is more secure, but beware that it leaves the newline character at the end of the string.
Don't do things like letter + 32
. Instead, use the functions in ctype.h
. In this case, use tolower
or toupper
.
Instead of passing i
as a pointer, just pass it as an int
and return the changed value.
Don't use printf
and scanf
to print/scan a single character. Instead use putchar
and getchar
.
Use ++i
instead of i += 1
.
Your typedef
just obscures things. If the declaration of (e.g.) printWords
is void printWords(char letter, char *sentence)
then a C programmer knows what's going on right away without having to know what string
is. The typedef
really adds nothing.