I am writing a program that gets a filepath-name from the command-line and then proceeds to open the file. My question is: Is it possible to create a string, the moment the user gives the input, that would be exactly the size needed for the filepath to fit into it? If not, what would be the ideal size for the non-dynamical char array I would have to use?
I just want to get rid of the hard-coded string size:
char filename[100];
scanf(" %s", filename);
It comes with so many problems.
Per the C standard the FILENAME_MAX macro (defined in stdio.h) specifies either the maximum or recommended length of file names (quote:
222) If the implementation imposes no practical limit on the length of file name strings, the value of FILENAME_MAX should instead be the recommended size of an array intended to hold a file name string.). I’d say, find out the filename length limits of your target OS.