If you don't want to pass it as an argument, you'll need to shove it in a global so that the function can access it that way. I know of no other means (other than silly things like writing it to a file in main()
and reading it in the function):
static char *x;
static void fn(void) {
char *y = x;
}
int main (int argc, char *argv[]) {
x = argv[1];
fn();
return 0;
}
This is not how I would do it. Since you need to be able to change fn()
to get access to x
anyway, I'd rewrite it to pass the parameter:
static void fn(char *x) {
char *y = x;
}
int main (int argc, char *argv[]) {
fn(argv[1]);
return 0;
}
Unless, of course, this is homework, or a brainteaser, or an interview question.