问题描述
我有一个函数(我从你们其中一个人那里窃取了代码
在comp.lang.c中):
void myStringClean(char *字符串){
char *指针;
if((pointer = strchr(String,''\ n''))!= NULL){
*指针=''\ 0'';
}
}
我该怎么称呼这个功能?我在main.c中这样打过电话:
myStringClean(myName);
我打电话时没有错误或警告
这样的功能
gcc -ansi -pedantic -Wall -W,
当我用它来调用它时
myStringClean( & myName);
我收到警告
从不兼容的指针类型传递''myStringClean'的arg 1。
mSC.h中的原型如下所示:
#include< string.h>
void myStringClean(char * String);
提前感谢您的回复。
-
未找到匹配项
I have a function(whose code I have stolen from one of you
in comp.lang.c):
void myStringClean(char *String) {
char *pointer;
if((pointer = strchr(String, ''\n'')) != NULL) {
*pointer = ''\0'';
}
}
How should I call this function? I''ve called like this in main.c:
myStringClean(myName);
I get no errors or warnings when I call
the function like this with
gcc -ansi -pedantic -Wall -W,
when I call it using
myStringClean(&myName);
I get the warnings
passing arg 1 of ''myStringClean'' from incompatible pointer type.
The prototype in mSC.h looks like this:
#include <string.h>
void myStringClean(char *String);
In advance thanks for helpful replies.
--
No matches found
推荐答案
myName的声明不是''char * myName;''。也许你正在使用
''char myName [N];''?
Mike
The declaration of myName is not ''char *myName;''. Perhaps you''re using
''char myName[N];''?
Mike
如果我上面的评论是正确的,那么& myName确实是不兼容的
与你的声明myStringClean。 myStringClean将一个指针
作为参数接受一个字符。 myName是一个指向角色的指针,所以
你的第一次尝试工作正常。但是,& myName是指向一个字符的指针
,这不是同一个东西。感谢gcc for
请指出这一点。
-
Christopher Benson-Manica |我*应该*知道我在说什么 - 如果我
ataru(at)cyberspace.org |不,我需要知道。火焰欢迎。
If my comment above is correct, then &myName is, indeed, incompatible
with your declaration of myStringClean. myStringClean takes a pointer
to a character as a parameter. myName is a pointer to a character, so
your first try works fine. &myName, though, is a pointer to a pointer
to a character, which is not the same thing. Say thank you to gcc for
kindly pointing this out to you.
--
Christopher Benson-Manica | I *should* know what I''m talking about - if I
ataru(at)cyberspace.org | don''t, I need to know. Flames welcome.
嗯...我只想说我期待并欢迎关于
* doh *
-
Christopher Benson-Manica |我*应该*知道我在说什么 - 如果我
ataru(at)cyberspace.org |不,我需要知道。火焰欢迎。
Um... let me just say that I expect and welcome comments about the
fact that I injudiciously called myName a pointer to a character...
*doh*
--
Christopher Benson-Manica | I *should* know what I''m talking about - if I
ataru(at)cyberspace.org | don''t, I need to know. Flames welcome.
这篇关于功能使用指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!