Modifier une char* dans une fonction
Bonjour,
voici mon code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| static bool ExtractVariableName (const char *Source, char* &DestName)
{
// The function look if the Source is a variable name and if it is, it extract just the name and stock it in DestName
// A variable in the document is specify with its name between brackets '[' and ']'
// If it is effectively a variable it return TRUE else it return FALSE
DestName = NULL;
if ((Source[0] == '[') and (Source[strlen(Source)-1]==']'))
{
const char* i = &Source[1];
char VariableName[strlen(i)];
strncpy(VariableName, i,strlen(i)-1);
VariableName[strlen(i)-1]='\0';
DestName = VariableName;
return true;
}
return false;
} |
Au retour de cette fonction, j'ai des soucis : la variable contient bien la bonne valeur, mais cette valeur est modifiée ensuite depuis un autre traitement qui n'a rien à voir.
Comment écrire correctement cette fonction ?
Merci d'avance pour vos réponses.