To open a file with a user supplied name, you would need to store the name in a variable. If the file name was to have no more than 20 characters in it, which would be an appropriate declaration of the file name variable? char filename; char filename[21]; char filename[20];
Real Tutor Solution
Answer
Solution
Sign in to Unlock Answers for Free!
A Learning Platform Trusted by Millions of Real Students and Teachers.
Reviewed and approved by the UpStudy tutoring team
Bonus Knowledge
To ensure that the filename can safely hold up to 20 characters, while also accommodating the null terminator that indicates the end of a string, the correct declaration would be `char filename[21];`. This allows for the maximum string length of 20 characters plus one additional character for the null termination. A common mistake when declaring arrays for strings is forgetting the null terminator, which can lead to bugs in string handling and file operations. Always remember to declare one extra space for the null character when you're working with fixed-size string arrays!