This is the code that was provided as starter code on which I have to answer a couple of question using the data provided in data.txt
file. data.txt
is kept in the same folder as my code and contains line separated words all of which are of length 21. I am familiar with C but I do not know anything related to files and file management.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
int main(void) {
char* fname = "data.txt";
FILE *fptr = NULL;
char line[20000][22];
int i = 0;
fptr = fopen(fname, "r");
while(fgets(line[i],20000,fptr))
{
line[i][strlen(line[i]) - 1] = '\0';
i++;
}
printf("Read a file with %d lines.\n",i);
}
When I run this code in CLion, the following error appears.
I am using LLVM clang compiler. The same error appears even if I use Microsoft Visual Studio compiler. It would be helpful if you can explain what the error means and how to resolve it!