Here is the code http://pastebin.com/Abk8GY3m. When the program prompts me for the name. It gives me the correct output. For example Robert Vicino gives the output RV. I compared it with the cs50 staff's own implementation of initials and it gives the same result. When checking for alternatives like Joseph Gordon-Levitt, Conan O’Brien as input, both programs output the same result.

But, when I type AA AA AA the output is AAAAAAAA instead of AAA. Can someone give me a hint why it does that? As I went through the code understanding deepen a bit is there something wrong with ? printf("%c", toupper (s[i+1]));

Also searched through a couple of posts here. Till now nothing helped.

When I type in vvvv then it also prints out vvvv.Which should not happen, the instructions state, that it should print out only the first character, of each word.

Why does this happen ? Can someone help me identifying the mistakes in the code or in my understanding of the code.


So when you say if (s[i] == s[0]), it doesn't compare i to 0, it compares the value of the string at index i to the value of the string at index 0, so when you type in AA AA AA, and it goes through the loop, it will see that the second letter is equivalent to A and print it. Then when it gets to a space character, you have printf("%c", toupper (s[i+1])), and in your string of 6 A's the character after the space is indeed another A, so it will print an A for each space as well.

Let me know if this needs clarification!

  • Thanks ! I found the solution now , it took me a while and had to read through other posts. Now I know why I did not work. The explanation helped a lot. – Dimitri Aug 29 '16 at 10:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .