Reputation: 5446
Is it possible to use a variable as a filename in function fopen()? Can someone help with some example?
Upvotes: 2
Views: 8257
Reputation: 134841
You just need a C string to pass into fopen()
. Just declare the string char *
(I'd recommend using const char *
) variable, set it and pass into the function.
const char *filename = "my/path/to/the/file";
FILE *file = fopen(filename, "r");
Upvotes: 5