0

Apologies for poor formatting, stil getting used to this. I aparently need meta stack exchange...

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

int main (void)  
{  
   int n;  
   int i=0;  
   printf("Enter your name:\n");    
   string name = get_string();        //get name to extract initials from
   n=strlen(name);  

   while (i<n)                            //Loop while position is less than name string length  
   {
      if(isalpha(name[i]) && isspace(name[i-1]));  //Print Character in uppercase if itis a lettter and there was a space in the spot before (aka first letter of name)  
      {
         printf("%s", toupper(name[i]));  
      }
   printf("\n");  
   i++;  
   }
}

This gives me the following compile error:

clang -fsanitize=integer -fsanitize=undefined -ggdb3 -O0 -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wshadow    initials.c  -lcrypt -lcs50 -lm -o initials
initials.c:18:23: error: format specifies type 'char *' but the argument has type 'int' [-Werror,-Wformat]
         printf("%s", toupper(name[i]));
                 ~~   ^~~~~~~~~~~~~~~~
                 %d
1
  • I have tried to change the data type of th einputs to line 18, but to no avail.
    – Mitch Beck
    Mar 16, 2017 at 19:23

1 Answer 1

0

Simply put, it's a type mismatch. The code is trying to put a char in a string. Change %s to %c

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

1
  • Thank you cliff! I knew it had to be something simple...
    – Mitch Beck
    Mar 16, 2017 at 23:05

You must log in to answer this question.

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