0

I've implemented the code for pset 2 initials (less) and it seems to be working, however, when I test it I get an error I'm struggling to understand. Any help would be greatly appreciated.

Below is my code:

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

int main(void)
{
    printf("What is your full name?\n");
    string name = get_string();

    if (name != NULL)
    {
        for (int i = 0, n = strlen(name); i < n; i++)
        {
            if (i == 0)
            {
                printf("%c", toupper(name[i]));
            }

            if (i > 0 && name[i] == ' ')
            {
                printf("%c", toupper(name[i+1]));
            }
        }
        printf("\n");
    }
}

And here are the errors I'm getting:

:) initials.c exists
:) initials.c compiles
:( outputs "MB" for "Milo Banana"
   \ expected prompt for input, not output of "What is your full name?\n"
:( outputs "MB" for "milo banana"
   \ expected prompt for input, not output of "What is your full name?\n"
:( outputs "RTB" for "Robert Thomas Bowden"
   \ expected prompt for input, not output of "What is your full name?\n"
:( outputs "R" for "ROB"
   \ expected prompt for input, not output of "What is your full name?\n"
:( outputs "RTB" for "Robert thomas Bowden"
   \ expected prompt for input, not output of "What is your full name?\n"
2

Did the instructions say to print "What is your full name?"

One of the hidden lessons of the first few psets is to write the code exactly to the specification. Any extra or missing prompts, spaces, text, chars, whitespace, line feeds, etc., will trigger a fail.

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

| improve this answer | |
1

Check the usage section of the initals page here:

http://docs.cs50.net/problems/initials/less/initials.html

Although your solution may be more user friendly, the problem does not expect you to prompt the user for their name. Thus when you run check50 it is expecting you to type your name after you run ./initials and when it instead receives your output printf statement it fails. If your code works correctly after that is another story however, so if you get stuck afterwards, feel free to ask another question.

| improve this answer | |

You must log in to answer this question.

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