As @SamGerber has mentioned, you have two obvious mistakes.
- You don't include the stdio.h library and so you can't use the
printf()
function that it includes.
scanf()
stands for scan formatted
so the string you are supposedly reading is just a sequence of char
s without any white-space in between, something that is not true in our case. See the specification for this pset:
Write, in a file called initials.c, a program that prompts a user for their name (using GetString
to obtain their name as a string
) and then outputs their initials in uppercase with no spaces or periods, followed by a newline (\n
) and nothing more. You may assume that the user’s input will contain only letters (uppercase and/or lowercase) plus single spaces between words. Folks like Joseph Gordon-Levitt
, Conan O’Brien
, and David J. Malan
won’t be using your program.
So there is no specification for the number of space separated names you are gonna be given. Could be one, could be two, could be three or even twenty!
So better use GetString()
as described by the spec and not scanf()
. It surly is possible to implement it using scanf()
, but it's not what you are asked for. You should learn to follow the instructions you are given. Even if you implemented the scanf()
correctly, you might not get a full grade because you haven't implement it the way it was supposed to be implemented.
- Aside from that, your
for loop
is also wrong. You shouldn't traverse all the 30 char
s (even though it's again not specified that the name is going to be less than 30 char
s). You should instead have used strlen()
and traverse only until the end of the string
.
Hope this helps you get going!
If this answers your question please accept it by clicking the gray check-mark to the left, so that it becomes green. You can also vote it up by pressing the up arrow above the check-mark. And don't forget to keep coding!