0

I have a problem of running this code. when i try to complie, it keeps repeating on the same warnings. Here's my code. enter image description here Here's the warning: initials.c:14:12: error: expression result unused [-enter image description here Can somebody help please? I have stuck on it for few days. pset2 is so hard!

2 Answers 2

0

Look at these two lines again:

char c = toupper(name[0]);
printf("%c", toupper(name[0]);

You're basically doing the same thing twice, so your variable 'c' is unused (just print 'c', no need to toupper again). Also, your printf statement is incorrect. You don't need the ':' in there. If you want ':' to be printed, you need to include it inside the brackets and quotations that go inside the printf's brackets.

1
  • OMG! thank you so much!!!
    – lucy shu
    Commented Sep 12, 2016 at 11:55
0

Look at these lines :-

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

Here, you have i = 0, but you are referencing to the value of name[i - 1] , which is outside the bounds of the string.

Also, as iCode95 has also mentioned , you don't have to put the colons outside the printf()'s .

Here, you are also printing a new line after every capitalized initial letter, as it is in a loop.But you have to print the new line after all the initials in the name.So, better have a new line after the for loop.

printf("%c\n", toupper(name[i]));

Also, i would suggest you to call strlen(name) only once, as it's never gonna change. So instead of keeping it in the condition part of the for loop, you can keep it either above the for loop or in its initialization part(as I have done). Just a better design pattern.

So, in a nutshell, you can do something like this.

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

You must log in to answer this question.

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