this was my code to read the content of "file.txt" that contains the following text :
hi farah
slay
and this is my c code :
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
FILE* fp = fopen("files/file.txt","r");
char str[20];
if (fp == NULL) {
printf("error");
exit(1);
}
while(!feof(fp)) {
fgets(str,5,fp);printf("%s",str);
}
fclose(fp);
return 0;
}
but instead of the file content i get this as an output
hi farah
slayslay