This is my main.c
:
#include
void changeStuff(char *stuff){
stuff= \"Hello everyone\";
}
int main(int argc, char **argv) {
In C, function arguments are passed-by-value. In order to modify a pointer value, you need to pass a pointer to the pointer, like:
#include <stdio.h>
void changeStuff(char **stuff){
*stuff= "Hello everyone";
}
int main(int argc, char **argv) {
char *stuff;
changeStuff(&stuff);
printf("%s\n", stuff);
return 0;
}
Note that it's not a good idea to directly pass user-defined values to printf()
. See: How can a Format-String vulnerability be exploited?