I have a text file that looks like this:
NAME:333
VALUE:555
TEST:355
REST:224
4444
I'm trying to check ahead for empty lines, and if found skip them (don't parse them), I'm also trying to check for white space (line wrapping). However, my code doesn't exactly work as it should:
int main(void) {
FILE*ptr;
ptr = fopen("test.txt","r");
if(ptr == NULL)
return 0;
while(fgets(buffer,sizeof(buffer),ptr) != NULL) {
if(buffer[0] == "\n") //blank line, skip it
continue;
else {
if(strcmp(buffer,"\r\n") == 0)
printf("Blank Space found\n");
}
}
return 0;
}
However, what's happening is that when a blank line is found, the else statement executes, instead of the if. (On a Ubuntu system ). So I'm not sure how to differentiate between completely empty lines, and lines with white space that possible wrap to the next line.
I also tried using strcmp to check for a blank line (explicitly in the if statement), but that never executed, even though there are 2 blank lines in my text file, any help would be greatly appreciated.