Answer the question
In order to leave comments, you need to log in
How to allocate dynamic memory for a text file in C?
I have a function:
FILE* openInputFile()
{
printf("Enter the name of the input file: ");
char* inputFileName;
scanf("%s", &inputFileName);
printf("%s", inputFileName);
if (strstr(inputFileName, ".txt") == NULL)
inputFileName = strcat(inputFileName, ".txt");
printf("%s", inputFileName);
FILE* inputFile = fopen(inputFileName, "r");
return inputFile;
}
Answer the question
In order to leave comments, you need to log in
char* inputFileName;
char inputFileName[256];
char *inputFileName;
inputFileName = (char *) calloc(256, 1);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question