B
Benoit Lefebvre
Weird subject you will say.. I didn't know what to put in there..
Long story short, I'm changing the value of a variable from a
function.. Nothing unusual there..
How come the value of the "word" variable change when using the
testfunct function? Am I sending a pointer to the word variable to
this function or whatever ??
I know it's a weird question.. especially that this is doing exactly
what I need.. but I want to know if I'm doing it right and if not, how
to make it work correctly.
The program where this is going is checking a configuration text file
and puts all the lines in a 2d char array for comparison later. Here
is a simplified "extraction" of the code.
------
#include <stdio.h>
#include <strings.h>
int testfunct (char *myword)
{
strcpy(myword,"hello");
return 0;
}
int main (int argc, char *argv[])
{
char word[100];
strcpy(word,"weeee");
printf("WORD: %s\n", word);
testfunct(word);
printf("WORD: %s\n", word);
return 0;
}
------
Long story short, I'm changing the value of a variable from a
function.. Nothing unusual there..
How come the value of the "word" variable change when using the
testfunct function? Am I sending a pointer to the word variable to
this function or whatever ??
I know it's a weird question.. especially that this is doing exactly
what I need.. but I want to know if I'm doing it right and if not, how
to make it work correctly.
The program where this is going is checking a configuration text file
and puts all the lines in a 2d char array for comparison later. Here
is a simplified "extraction" of the code.
------
#include <stdio.h>
#include <strings.h>
int testfunct (char *myword)
{
strcpy(myword,"hello");
return 0;
}
int main (int argc, char *argv[])
{
char word[100];
strcpy(word,"weeee");
printf("WORD: %s\n", word);
testfunct(word);
printf("WORD: %s\n", word);
return 0;
}
------