objective-c - 将 char 传递给 c 中的函数(这本书错了吗?)

标签 objective-c c char

我正在阅读“Objective-C Programming The Big Nerd Ranch Guide”这本书


他们给出了这个代码:

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

并用这个调用它:

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

这给了我这个警告:

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

这本书有错吗?

最佳答案

可能有错别字。

Char表示单引号中只有一个字符,如'a'

常量字符串在双引号中并衰减为 char* 或字符指针,如下所示。

"Hello World"

关于objective-c - 将 char 传递给 c 中的函数(这本书错了吗?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12828054/

相关文章:

c - 跳入循环

c# - C# 16 位字符如何编码所有 Unicode 字符?

C++ 将 char 值(通过使用堆栈弹出)分配给 char*

ios - 在 Swift 中使用 'Any' 有什么意义?什么时候使用 'Any' 什么时候使用 'AnyObject' ?

iphone - NSURLConnection 和 JSON 数据

objective-c - 使用 NSImage 的垃圾收集崩溃

c++ - C++中char[]的子串

objective-c - UIAlertView clickedButtonAtIndex 未调用

C 增加 char 数组的大小

c++ - 为什么这个输出?