I'm new to C, and I'm trying to make a string of variable length, like this:
int main(int argc, char *argv[]) {
if (argc > 1) {
char filename[] = argv[1];
}
else {
char filename[] = "temp.txt";
}
printf("%s", filename);
}
Of course, that doesn't work because the scope of the string is only within the conditional statement.
How can I assign this variable to a string of an unknown length based on conditional statements?