I am trying to read in a file and then check to see if it contains a new line,tab or space.
I am currently reading in the file with fgets()
and then checking line by line to see if the file contains a new line,space or tab.
#include <stdio.h>
#include <string.h>
int main(){
FILE* fp;
char line[255];
int nonBlankLines = 0;
int totalLines = 0;
fp = fopen("Test.java","r");
while(fgets(line,sizeof(line),fp)){
if(line != '\n' || line != '\t' || line != '\n'){
nonBlankLines++;
}
totalLines++;
printf("%s\n",line);
}
fclose(fp);
printf("The total lines are %d \n", totalLines);
printf("The total non blank lines are %d \n", nonBlankLines);
}
When I compile and run the program, both the total lines and blank lines are the same number.
Here is the java file I am trying to examine:
/**
* This is the first line in the comment.
* This is another line in the comment.
* The comment ends on the line below.
*/
class Hello{
public static void main(String[] args){
System.out.println("Hello");
}
}
there are 2 empty lines near the bottom of the java
file my program is not picking up on.
How do I get my program to read these characters?