1

I'm reading the book "Objective-C Programming The Big Nerd Ranch Guide".


They give out this code:

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);
}

and call it with this:

congratulateStudent("Mark", "Cocoa", 5);

This gives me this warning:

Format specifies type 'char *' but the argument has type 'char'

Is the book wrong?

4

4 回答 4

2

可能有错别字。

Char仅表示单引号中的一个字符,如'a'.

一个常量字符串在双引号中并衰减为一个char*或字符指针,就像这样。

"Hello World"
于 2012-10-10T20:49:37.177 回答
1

是的,如果这是书上所说的,那绝对是一个错误,它应该是 char * 作为方法中的参数,就像警告所说的那样。

于 2012-10-10T20:49:19.923 回答
1

是的,这是不正确的。也许是打印错误。只需让他们指针:

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

从技术上讲,在 C 中将不正确的格式字符串传递给printf.

于 2012-10-10T20:49:34.340 回答
0

是的,这本书有一个错字。

您应该使用char*而不是charC 函数的两个参数

于 2012-10-10T20:49:25.993 回答