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

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

   for (int i = 0, n = strlen(name); i < n; i++)
   {

         if ( i == 0 )
         {
            if (name[i] >= 'A' && name[i] <= 'z')
            {
                printf("%c", toupper(name[i]));
            }
         }

          else if (name[i-1] == ' ')
        {
            if (name[i] >= 'A' && name[i] <= 'z')
            {
                printf("%c", toupper(name[i]));
            }


        }
     }

        printf("\n");
}

output

//~/workspace/pset2/ $ check50 2016.initials.more initials.c
:) initials.c exists
:) initials.c compiles
:) outputs "MB" for "Milo Banana"
:) outputs "MB" for "milo banana"
:( outputs "MB" for " milo  banana "
   \ expected output, but not "NEYM NEYB NEY\n"
:( outputs "MB" for "  milo banana  "
   \ expected output, but not "NEY NEYMB NEY NEY\n"
:( outputs "RTB" for "   robert   thomas bowden"
   \ expected output, but not "NEY NEY NEYR NEY NEYTB\n"
:) outputs "RTB" for "Robert Thomas Bowden"
:) outputs "R" for "ROB"
:) outputs "RTB" for "Robert thomas Bowden"//

1 Answer 1

0

Your code works well. I'd use isalpha(name[i]) instead of name[i] >= 'A' && name[i] <= 'z', but for the test cases, your code works well.

Maybe you forgot to save the file before compiling, or forgot to make initials before running check50?

2
  • I don't think its either of those. Just tried your recommendations.Thanks btw Mar 10, 2017 at 9:52
  • The "NEY" is not part of the code you shared, that's why I assume you removed it, but forgot to save before submission, or saved in a different directory, or another name. My remark on make initials is completely wrong, as check50 would take the source code, not the compiled file.
    – Blauelf
    Mar 10, 2017 at 15:17

You must log in to answer this question.

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