0

您好,当我尝试将 char 传递给函数时出现错误。这是我的代码。

多变的

char *temp;

原型

int checkIfUniqueCourseNo(char,int);

称呼

checkIfUniqueCourseNo(temp,k);

和我的错误

warning: improper pointer/integer combination: arg #1

我是 C 新手,所以对我放轻松:)

4

3 回答 3

2

您的函数接受char; 您正在尝试传入char*.

要解决此问题,您需要取消引用指针以获取它指向的字符,以便您的函数接收它期望的参数类型:

checkIfUniqueCourseNo(*temp,k);
于 2012-04-27T14:18:50.040 回答
0

如果函数 excepts char,您应该取消引用指针:

checkIfUniqueCourseNo(*temp,k);
//                    ^ pass the char addressed by temp
于 2012-04-27T14:18:58.030 回答
0

你的变量是一个char*(字符指针),但函数需要一个char(不是指针)。

如果要将temp的内容checkIfUniqueCourseNo(*temp, k)传递给函数,请使用. 如果您确实想传递指针本身,请将函数声明为

int checkIfUniqueCourseNo(char*,int);
于 2012-04-27T14:20:28.557 回答