im trying to read a .txt file, line by line, where each line is 19 characters long, this is my code (I want to only use fseek and fread to understand pointers rightly):
int main(int argc, char *argv[]){
FILE *file = fopen(argv[1], "r");
if(file == NULL){
perror("fopen");
return 0;
}
int i = 0;
int j = 0;
char L[20];
while(1){
if(feof(file)){
break;
}
fseek(file, i*20, SEEK_SET);
fread(L,19,sizeof(char),file);
printf("%s\n", L);
i++;
}
fclose(file);
return 0;
}
What I think should happen with this is that I move the pointer to the file to the start of each line in a loop, then move one line and so. The source .txt file is:
123456789:123456789
perro:guau
gato:miau
vaca:muuu
lobo:auuu
while the output I get from my program is:
123456789:123456789�V
perro:guau �V
gato:miau �V
�V
vaca:muuu �V
�V
lobo:auuu �V
�V
�V
I tried changing the 20s and 19s since I dont know if im including the end of string character in the right way, but got even worse results, any help would be apreciated.