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 (name[i-1] == ' ' || (i == 0 && name[i] != ' '))
        {
            char uppercase = (char) (toupper((int) name[i] - 32));
            printf("%c", uppercase);
        }    
    }

    printf("\n");
}

When I run check50, it throws this back at me https://sandbox.cs50.net/checks/5d4b67d174d5409c9b1ca38486a8d980

0

Quite simply, your program isn't producing the correct output. look at the following:

char uppercase = (char) (toupper((int) name[i] - 32));

The assignment is to capitalize the initials. So, after capitalizing them with the call to toupper() (btw, the casting to char and to int isn't necessary), why are you subtracting 32 and corrupting the output?

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

You must log in to answer this question.

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