I have a file named DB.txt, I read lines in a for loop and print those lines out but the ting is nothing prints out. I think it’s important to mention that I’m coding in CLion on MAC because there were always some issues when I worked with files (e.g. I tried to write into a file but instead of what I inputed I always got trash in this file33)
so my code now looks like this
int fileInput(struct nn *record){
FILE *f;
f = fopen("DB.txt", "r");
char buffer[80];
if(f == NULL){
printf(stderr, "Cannot open file");
return 1;
}
while (fgets(buffer, sizeof(buffer), f) != NULL) {
printf("%s", buffer);
}
// int j = 0;
// char *token = strtok(buffer, " ");
// while(token != NULL){
// strcpy(record[x].params[j], token);
// token = strtok(NULL, " ");
// j++;
// }
// x++;
}
}
fclose(f);
return 1;
}
(the commented part is supposed to split the line by spaces and add each string to a struct array, but for now it’s irrelevant)
and I just don’t get why it doesn’t print anything