0

So I wrote my code for initials and when I test it myself everything runs perfectly, but when I check it using check50 2015.fall.pset2.initials initials.c the checking program says that I have the expected output, but with extra \ns. For example:

:( outputs "MB" for "Milo Banana" \ expected output, but not "-\n\"\n"

:( outputs "MB" for "milo banana" \ expected output, but not "M\nB\n"

:( outputs "RTB" for "Robert Thomas Bowden" \ expected output, but not "2\n4\n\"\n"

and so on. This is my code, if anyone could tell me what the problem is with it and why it doesn't check out perfectly that would be great!

include

include

include

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

if (s != NULL)
{
    printf("%c\n", (s[0]) - ('a' - 'A'));

    for (int i = 0;  i <= strlen(s); i++)
    {
        if (s[i] == ' ')
        {
            printf("%c\n", (s[i + 1]) - ('a' - 'A'));
        }
    }
}

}

0

you are printing two new line '\ n', you should delete and print new line only at the end of main

0

Mars' observation is indeed correct and important, as it will prevent your program from passing check50. First, some advice on reading check50 error message for this pset:

This is what it expects

outputs "RTB" for "Robert Thomas Bowden"

This tells you that you did in fact generate output:

\ expected output,

And this tells you what output your program produced:

but not "2\n4\n\"\n"

The example in the pset instructions is very specific about what the autograder (check50) expects:

username@ide50:~/workspace/pset2 $ ./initials
robert thomas bowden
RTB

It looks like your program produced this for the similar test in check50 (which should produce the same output as the example above):

username@ide50:~/workspace/pset2 $ ./initials
Robert Thomas Bowden
2
4
"

Remember in the example from capitalize-0, David only used this notation (s[0]) - ('a' - 'A')); for lower case letters. You will find the direction you need in the week 2 examples videos.

You must log in to answer this question.

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