功能使用指针 [英] Function Using Pointers

查看:68
本文介绍了功能使用指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个函数(我从你们其中一个人那里窃取了代码

在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

推荐答案

首先,如果您希望收到对您问题的回复,我建议您从新闻阅读器中删除''hannibalkannibalATyahooDOTno''
$ b'b配置为''Followup-To''字段。


周一,2004年1月5日15:43:09 -0500,Eirik WS写道:
First, if you would like to receive replys to your question, I
recommend removing ''hannibalkannibalATyahooDOTno'' from your news reader
configuration for the ''Followup-To'' field.

On Mon, 05 Jan 2004 15:43:09 -0500, Eirik WS wrote:
当我使用
myStringClean(& myName)调用它时;
我收到警告
从不兼容的指针传递''myStringClean'的arg 1类型。
when I call it using
myStringClean(&myName);
I get the warnings
passing arg 1 of ''myStringClean'' from incompatible pointer type.




myName的声明不是''char * myName;''。也许你正在使用

''char myName [N];''?


Mike



The declaration of myName is not ''char *myName;''. Perhaps you''re using
''char myName[N];''?

Mike


Eirik WS< hx ****************************** @ xyxaxhxoxox.no>这样说:
Eirik WS <hx******************************@xyxaxhxoxox.no > spoke thus:
void myStringClean(char * String){
char * pointer;
if((pointer = strchr(String,''\ n') '))!= NULL){
* pointer =''\''';
}
}
我该如何调用此函数?我在main.c中这样调用过:
myStringClean(myName);
当我用
gcc -ansi调用
这个函数时我没有错误或警告-pedantic -Wall -W,


我这用来表示myName被声明为


char myName [512]; / *或者* /

当我用
myStringClean(& myName)调用它时;
我收到警告
传递''myStringClean'的arg 1 '来自不兼容的指针类型。
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,
I take this to indicate that myName is declared as

char myName[512]; /* or something */
when I call it using
myStringClean(&myName);
I get the warnings
passing arg 1 of ''myStringClean'' from incompatible pointer type.




如果我上面的评论是正确的,那么& 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.


Christopher Benson-Manica< at *** @ nospam.cyberspace.org>这样说:
Christopher Benson-Manica <at***@nospam.cyberspace.org> spoke thus:
char myName [512]; / *或者某些东西* /
如果我上面的评论是正确的,那么& myName确实与你的myStringClean声明不兼容。 myStringClean将一个指针
作为参数。 myName是一个指向角色的指针,所以
你的第一次尝试工作正常。但是,& myName是指向字符的指针,这不是同一个东西。感谢gcc for
请指出这一点。
char myName[512]; /* or something */ 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.




嗯...我只想说我期待并欢迎关于<的评论事实上,我不明智地将myName称为指向角色的指针...

* 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.


这篇关于功能使用指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆