Jordan Taylor said:
#include<stdio.h>
void f(char **c)
{
*c=(char*)malloc(sizeof(char)*6);
}
int main()
{
char *c;
f(&c);
printf("%s\n", *c);
return 0;
}
I'm trying to get the printf to print hello, but I tried memcpy(*c,
"Hello", 6) and it doesn't help. Is my memory allocation correct?
Aside from the other advice you've gotten, you use the name "c" for
the char** parameter to f() and for the char* variable in main().
That's bound to cause confusion.
You tell us that you tried memcpy(), but you didn't actually show us a
program with a call to memcpy(). We can't guess where you added the
memcpy() call (especially since there are two different things called
"c" in your program) or what else you might have changed at the same
time. Show us real code. "Doctor, I've been having headaches. I'll
send my brother to see you; he doesn't have headaches, but I'm sure
you can diagnose my problem by examining him."
Finally, telling us "... and it doesn't help", um, doesn't help. I'm
sure there are a large number of things your program doesn't do.
Telling us what it *does* do is far more helpful. Don't tell us it
doesn't work; tell us exactly *how* it doesn't work.
If any of this sounds harsh, it's not intended that way. Asking good
questions isn't easy. <
http://www.catb.org/~esr/faqs/smart-questions.html>
is a good guide.
And since you're posting through Google, please read
<
http://cfaj.freeshell.org/google/>.