For initials.c I've coded so I have the correct output of the initials in capital letters but when I run check50 it says it is incorrect. I've changed my code multiple times with the \n within the loop and outside at the end etc and still get error messages.
Anyone know what I am doing wrong?

Here's the error:
:) initials.c exists
:) initials.c compiles
:( outputs "MB" for "Milo Banana"
\ expected output, but not "B\n"
:( outputs "MB" for "milo banana"
\ expected output, but not "B\n"
:( outputs "RTB" for "Robert Thomas Bowden"
\ expected output, but not "TB\n"
:( outputs "R" for "ROB"
\ expected output, but not "\n"
:( outputs "RTB" for "Robert thomas Bowden"
\ expected output, but not "TB\n"

Here's my code:

#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <ctype.h>

    int main(void)
      string name=GetString (); 

      for (int i = 0; i < strlen(name); i++)
             if (name[i] == ' ' && name[i+1] != '\0')
             printf("%c", toupper(name[i+1]));

1 Answer 1


Actually, you haven't coded the correct output. It's clear from the check50 report that you are not outputting the first initial, only initials that follow a space. The first initial is a special or corner case - the first letter in the input.

If this answers your question, please click on the check mark to accept. Let's keep up on forum housekeeping. ;-)

  • Ah okay, I can see that from the code now. Strange as when I was running the program it was giving the correct output but I must have been accidentally putting a space before typing the name.
    – Helen
    Nov 22, 2015 at 20:57
  • All fixed now, thanks!! :) outputs all around
    – Helen
    Nov 22, 2015 at 21:00

You must log in to answer this question.

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