-1

I just finished the initials.c problem. I tried making it with my own function "initialize()". Is it written correct?

// Prototypes
int initialize(string name);

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

    printf("\n");
}

int initialize (string name)
{
    printf("%c", toupper(name[0]));

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

The function initialize returns an int so you need to declare an int in your main function to receive it. You're also printing the first character of the string twice.

1
  • You don't need to declare an int to receive what initialize returns. Also, the code doesn't print the first char of the string twice. It prints the first letter, and if it finds a space after that, it prints the letter after the space.
    – David
    Nov 4 '15 at 22:45
0

I think you should experiment with your code. If it works, you did it right. If it doesn't, there might be compiling errors, or you might not get what you wanted as a result. You can use this to fix your code.

If by "written correct" you mean style, in the declaration (not the prototype) of your 'initialize' function, there usually isn't a space between the function name and the parameters it takes.

EDIT: Your function initialize should be of type void. It doesn't need to return anything. Main only returns zero to say that there were no errors and everything went well.

You must log in to answer this question.

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