I would like to strcpy() the content of the memoryblock pointed on by my_pointer to my_variable.Of course it does not work. How can I solve it?Code:strcpy (my_variable, my_pointer);
Thank You.
I would like to strcpy() the content of the memoryblock pointed on by my_pointer to my_variable.Of course it does not work. How can I solve it?Code:strcpy (my_variable, my_pointer);
Thank You.
my_variable should have enough memory allocated to it.
IOW:
Of course, my_pointer should be pointing to a string in this case.Code:char my_variable[MAX_ARRAY]; .. .. .. strcpy(my_variable, my_pointer);
Unfortunately the compiler tells me that now parameter 2 cannot be changed from 'char' to 'const char*'...
You'll need to post more code.
Preferably the declaration of my_pointer and my_variable and where you allocate memory for my_pointer.
my_pointer is probably pointing to a single char rather than a string.
(ok, it's my first script in c++ so it became a little dirty... and long... and over-nested...)
I employ strtok() in one part of the programm and get char* var_Desk. Then I want to check, what var_Desk contains and return either var_Desk as var_Deskcheck or "0" as var_Deskcheck.
(I my code "my_variable" is "var_Deskcheck" and "my_pointer" is "var_Desk".)Code:char fnc_Interpret (char lkv_Desk) { char var_Deskcheck [8]; if (lkv_Desk != 0) strcpy (var_Deskcheck, lkv_Desk); else if (lkv_Desk == 0) strcpy (var_Deskcheck, "0"); return var_Deskcheck; }
Thanks.
@ elad:
I thought I pointed to whatever strtok() returns, but I found no explicit explanation what strtok() really does...
Lots of problems here:
- It's complaining because lkv_Desk is type char. You're passing it into strcpy which takes type char*
- And what's the purpose of this comparison?
(lkv_Desk != 0)
If you're checking for the NULL case then your else statement can simply be
var_Deskcheck[0] = '\0';
- return var_Deskcheck;
You can't do this because your char array will be out of scope after you've returned it. Either make a global char array or better yet, do a malloc and return the pointer.
Is this what you want?
Code:char* fnc_Interpret (char* lkv_Desk) { char* var_Deskcheck; var_Deskcheck = malloc(sizeof(char)*8); if (lkv_Desk != NULL) strcpy (var_Deskcheck, lkv_Desk); else var_Deskcheck = NULL; return var_Deskcheck; }
Last edited by Cshot; 10-03-2002 at 01:43 PM.
Try not.
Do or do not.
There is no try.
- Master Yoda