greetings

just started with C/C++. Im not quite comfortable porting from java to c/c++. Pointers are quite hard at start. So pls help me with this problem

I want to copy the exact data of a certain pointer to an array of struct. Not just point a pointer from another. can this be done???

example(not a struct just to prove some point.)

char* a="dashdkasdhk";

char* b;
b=a;

this would say that "b" is pointing to the address of "a".
so how can i assign "b" with the values of "a" but "b" have its own memory alocation of its own. no just pointing to "a"

If you're copying something, you need to allocate memory and then copy the appropriate values in. When dealing with strings, however, there's several library functions that'll help you along the way:

char* a = "hello world";
char* b;
b = strdup(a); // allocates and makes a copy of a
// ...
free(b);

would that work on structs? any alternative? lets say a more general way to solve it.

thanks

solve the prob. hehehe

thanks Infarction

i have a string of pointers
char *str[];

i want to pass str[1] into another function as argument.How to do it?
I have tried using
makefunc(&str)

//Definition: char makefunc(char *fun[])
--How to pass str?


Thanks

commented: Don't bump old threads -1

Just use std::string and avoid all this char* nonsense.

I also met this problem. Anyone can explain more , please?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.