C
cylin
Dear all,
I met a char pointer problem. please help,thanks.
How to change the the value which is pointed by a char pointer by a
function?
for example,
-----------------------------------------------------
#include <iostream>
using namespace std;
void addstr(char *str,int len) {
str=new char[len];
for (int i=0;i<(len-1);i++)
{
*(str+i)=char(65+2*i);
}
}
int main()
{
char *test;
int len=10;
addstr(test,len);
for (int i=0;*(test+i);i++)
cout << "here=" << *(test+i);
cout << endl;
}
---------------------------------------------------
Why does *test still equal to NULL?
How do I fix the function addstr so that test=str?
Best Regards,
cylin.
I met a char pointer problem. please help,thanks.
How to change the the value which is pointed by a char pointer by a
function?
for example,
-----------------------------------------------------
#include <iostream>
using namespace std;
void addstr(char *str,int len) {
str=new char[len];
for (int i=0;i<(len-1);i++)
{
*(str+i)=char(65+2*i);
}
}
int main()
{
char *test;
int len=10;
addstr(test,len);
for (int i=0;*(test+i);i++)
cout << "here=" << *(test+i);
cout << endl;
}
---------------------------------------------------
Why does *test still equal to NULL?
How do I fix the function addstr so that test=str?
Best Regards,
cylin.