I have a file with 6.321.078 records, they are formed by couple of integers separated by a comma. My aim is to read line by line and save it inside a char array (so, strings). My trouble is , when I run sscanf() it doesn't work. I think that this is the problem but I'm not sure that is the only one. I know that the file contain INT, but I need to save every line such as string. What can I do and why does not it work? (There is an example of my file.csv below)
main.c:
int main() {
FILE *fd;
char *arr;
arr = (char *)malloc(6321078);
for (int k = 0; k < 6321078; k++) {
arr[k] = calloc(20, sizeof(char));
}
char *r;
int pos = 0;
int n;
fd = fopen("file.csv", "r");
if (fd == NULL) {
perror("Error");
exit(1);
}
while (fgets(r, sizeof(r), fd) != NULL) {
sscanf(r, "%s", arr[pos]);
printf("%s", arr[pos]);
pos++;
}
}
Example of file.csv:

arr[k] = calloc(20, sizeof(char));that doesn't make sense asarrhas not been allocated as an array ofchar *but rather an array ofchar.char *r; fgets(r,sizeof(r),fd)that is undefined behaviour asris an unintialised pointer. Andsizeof(r)will give just the size of a single pointer.