本文介绍了传递char数组的单个项的地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!


我目前在使用c ++解析char数组时遇到了一些问题。 (并且

是的,我是半新手;-))也许你可以帮我这个:


#include< iostream>


使用std :: cout;


void outchar(char * outcharstring)

{

cout<< outcharstring;

}


void ftest(char * teststring)

{

int i = 0;


而(teststring [i]!=''\''')

{


outchar(& teststring [i]);

i ++;


}


}


int main()

{

char test [] =" Hello。" ;;


ftest(测试);


}


当然,这只是一个示例程序。但基本上我想要

来提供一个函数,需要一个字符串的地址,一个字符,这是另一个字符串的一个项目。


上面代码的输出是:

Hello.ello.llo.lo.o ..


我想要什么只是你好。。我怎么能做到这一点?


谢谢大家。


丹尼斯

Hi all!

I''m currently having some problems parsing a char array in c++. (And
yes, I''m a half-newbie ;-)) Perhaps you can help me with this:

#include <iostream>

using std::cout;

void outchar(char *outcharstring)
{
cout << outcharstring;
}

void ftest(char *teststring)
{
int i=0;

while (teststring[i] != ''\0'')
{

outchar(&teststring[i]);
i++;

}

}

int main()
{
char test[]="Hello.";

ftest(test);

}

Of course, this is just a sample program. But basically I would like
to give a function, that needs the adress of a string, a char, that is
one item of another string.

The output of the code above is:
Hello.ello.llo.lo.o..

What I would like is just "Hello.". How can I accomplish this?

Thanks everybody.

Dennis

推荐答案




怎么样叫outchar而不是ftest?


再见,

Chris Dams



What about calling outchar instead of ftest?

Bye,
Chris Dams





void outchar(char outchar)

{

cout<< ; outchar;

}


所以你只给这个函数一个字符。或者使用你的功能而不是

ftest



void outchar(char outchar)
{
cout << outchar;
}

so you give only one char to the function. or use your function istead of
ftest











如何调用outchar而不是ftest?



What about calling outchar instead of ftest?




好​​主意!也许OP希望用

字符输出字符串字符,您怎么看?


Chris



Great idea! Probably the OP wants to output the string character by
character, what do you think?

Chris


这篇关于传递char数组的单个项的地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 05:24