Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix error Format specifies type 'char *' but the argument has type 'char'

I get a warning saying: "Format specifies type 'char *' but the argument has type 'char'" for the student variable. I am copying/pasting the code out of a book into xcode and am not sure how to fix this. The only thing that prints in the console is "(lldb)". Any advice

#include <stdio.h>

void congratulateStudent(char student, char course, int numDays)
{
    printf("%s has done as much %s Programming as I could fit into %d days.\n", student, course, numDays);
}

int main(int argc, const char * argv[])
{
    // insert code here...
    congratulateStudent("mark", "Cocoa", 5);
    return 0;
}
like image 942
sharataka Avatar asked Dec 26 '12 10:12

sharataka


2 Answers

void congratulateStudent(char *student, char *course, int numDays)

the %s means that you are going to print a string ( array of chars)

and char student this means that student is a char type

so student here is not a pointer to a string

In order to change the student type from char to a string pointer you have to add asterisk to student char *student

In your code you are calling the congratulateStudent with input parameter string "mark". So to support this string the input parameter student should be defined as pointer of string

so you are missing the asterisk in the definition of student

The same thing for course

like image 158
MOHAMED Avatar answered Nov 08 '22 07:11

MOHAMED


void congratulateStudent(char *student, char *course, int numDays)

Use Function signature like because you are passing string as argument to function in main but function has character type argument..

like image 1
Adeel Ahmed Avatar answered Nov 08 '22 08:11

Adeel Ahmed