如何修复错误格式,指定类型为"char *",但参数为类型"char" [英] How to fix error Format specifies type 'char *' but the argument has type 'char'
问题描述
我收到警告说: 对于学生变量,格式指定类型为'char *',但参数的类型为'char'".我正在将代码从一本书中复制/粘贴到xcode中,并且不确定如何解决此问题.控制台中唯一显示的内容是(lldb)".任何建议
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;
}
推荐答案
void congratulateStudent(char *student, char *course, int numDays)
%s
表示您将要打印一个字符串(字符数组)
the %s
means that you are going to print a string ( array of chars)
和char student
这表示学生是char
类型
所以这里的学生不是指向字符串的指针
so student here is not a pointer to a string
要将学生类型从char更改为字符串指针,您必须向学生char *student
In order to change the student type from char to a string pointer you have to add asterisk to student char *student
在您的代码中,您正在使用输入参数字符串"mark"
调用congratulateStudent
.因此,要支持此字符串,应将输入参数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
与course
这篇关于如何修复错误格式,指定类型为"char *",但参数为类型"char"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!