0

I've written a successful program to complete the Initials section of Pset2 without the use of any functions. However, seeing as I needed to copy/paste a good chunk of code in my program I've decided to declare the copy/pasted part into it's own function and try to get the program to run with that way. Now, unfortunately, I am having problems getting program to compile. Through trial and error I've whittled my errors down to just 1, which reads the following:

initials2.c:32:22: error: unused parameter 'name' [-Werror,-Wunused-parameter]

void PrintCap(string name)

The function I am trying to utilize is for capitalizing each initial. (Note: I am aware of the toupper function within the cstyle lib but as this has not been covered in the course material I am wanting to solve the problem without it.) Any help in assisting me to get this program up and running with this function would be greatly appreciated. Here is my code:

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

void PrintCap(string name);
char a;
int main(void) 
{
   // get name
   printf("Please enter your name: ");
   string name = GetString();

   // print first initial capitalized
   a = name[0];
   PrintCap(name);

   // print following initials capitalized
   for (int i = 0, j = strlen(name); i < j; i++)
       {
        if (name[i] == 32)
           {
            a = name[i +1];
            PrintCap(name);
           }
       }
   printf("\n");   
}

// print capital letter function 
void PrintCap(string name)
{
   if (a >= 97 && a <= 122)
      {
        printf("%c", a - 32);
      }
   else 
      {
        printf("%c", a);
      } 
}
0
0

Your program is functional on my VM, but since it doesn't work on yours:

PrintCap(string name) gets called on line 15, where it takes name as its argument. Then, inside the function, on line 30-40 it never actually uses its parameter name, so name becomes an unused parameter.

1
  • 1
    Instead of having a global var a and passing name, why not have a as a local var in main and pass a instead of name as a parameter? Or better yet, eliminate a completely and just pass name[i +1] as a parameter?
    – Cliff B
    Oct 12 '16 at 2:28

You must log in to answer this question.

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