I have the following data.txt file that I am reading:
b 1
b 2
b 3
b 4
It is a tab in-between
I have the following code to print it out, line by line, then character by character.
#include <stdio.h>
#include <stdlib.h>
int printCharArray(char *arr);
int main(int argc, char * argv[]){
FILE * filePointer;
filePointer = fopen("data.txt", "r");
char singleLine[32];
while(!feof(filePointer)){
fgets(singleLine, 32, filePointer);
printCharArray(singleLine);
}
fclose(filePointer);
return 0;
}
int printCharArray(char *arr){
int length = 5;
printf("\n");
int i = 0;
for(i=0;i<length;++i){
printf("%c, ", arr[i]);
}
printf("DONE PRINTING \n");
return 0;
}
What confuses me is what it prints out:
b, , , , 1, DONE PRINTING
b, , , , 2, DONE PRINTING
b, , , , 3, DONE PRINTING
b, , , , 4, DONE PRINTING
I don't understand what there are 3 spaces between the letter and the number. If they're all chars, shouldn't there just be one space for the tab, and that's it?