简体   繁体   English

将char指针传递给函数错误

[英]Passing char pointer into a function error

Hello I'm getting an error when i try to pass a char through to a function. 您好我在尝试将char传递给函数时收到错误。 here is my code. 这是我的代码。

variable 变量

char *temp;

Prototype 原型

int checkIfUniqueCourseNo(char,int);

Call 呼叫

checkIfUniqueCourseNo(temp,k);

and my error 和我的错误

warning: improper pointer/integer combination: arg #1

Im new to C so go easy on me :) 我是C新手,所以对我很轻松:)

Your function accepts a char ; 你的函数接受一个char ; you are trying to pass in a char* . 你正试图传递一个char*

To fix this you need to dereference your pointer to obtain the character that it points to, so that your function receives the type of argument it expects: 要解决此问题,您需要取消引用指针以获取它指向的字符,以便您的函数接收它所期望的参数类型:

checkIfUniqueCourseNo(*temp,k);

If the function excepts char , you should dereference the pointer: 如果函数除了char ,你应该取消引用指针:

checkIfUniqueCourseNo(*temp,k);
//                    ^ pass the char addressed by temp

Your variable is a char* (char pointer), but the function takes a char (not a pointer). 您的变量是char* (char指针),但该函数采用char (不是指针)。

If you want to pass the contents of temp to the function, use checkIfUniqueCourseNo(*temp, k) . 如果要将temp的内容传递给函数,请使用checkIfUniqueCourseNo(*temp, k) If you really do want to pass the pointer itself, declare the function as 如果您确实想要传递指针本身,请将该函数声明为

int checkIfUniqueCourseNo(char*,int);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM