I have been making a program to read/search for keywords. I have it all figured out except how to read for blank lines. I am currently using "" but that of course, is just reading total lines. The only other thing I could think of was "/n" for keywords, but I believe that would not work either.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
char keywords[16][10]={"","","//","/*","int","char","float","double","if","else","for","switch",";","struct","[]","{}"};
char str[1000];
int variable=0;
int character=0;
int ifStatement=0;
int forStatement=0;
int switchStatement=0;
int elseStatment=0;
int semiColon=0;
int arrays=0;
int blocks=0;
int blankLines=0;
int comments=0;
int totalLines=0;
int structs=0;
FILE * fpointer;
fpointer = fopen("test2.txt", "r");
while(!feof(fpointer))
{
fgets(str,sizeof(str),fpointer);
puts(str);
if(strstr(str,keywords[0]))
{
totalLines++;
}
if(strstr(str,keywords[1]))
{
blankLines++;
}
if(strstr(str,keywords[2]))
{
comments++;
}
if(strstr(str,keywords[3]))
{
comments++;
}
if(strstr(str,keywords[4]))
{
variable++;
}
if(strstr(str,keywords[5]))
{
variable++;
}
if(strstr(str,keywords[6]))
{
variable++;
}
if(strstr(str,keywords[7]))
{
variable++;
}
if(strstr(str,keywords[8]))
{
ifStatement++;
}
if(strstr(str,keywords[9]))
{
elseStatment++;
}
if(strstr(str,keywords[10]))
{
forStatement++;
}
if(strstr(str,keywords[11]))
{
switchStatement++;
}
if(strstr(str,keywords[12]))
{
semiColon++;
}
if(strstr(str,keywords[13]))
{
structs++;
}
if(strstr(str,keywords[14]))
{
arrays++;
}
if(strstr(str,keywords[15]))
{
blocks++;
}
}
printf("Number of total lines = %d\n",totalLines);
printf("Number of blank lines = %d\n",blankLines);
printf("Number of comments = %d\n",comments);
printf("Number of variables = %d\n",variable);
printf("Number of if statements = %d\n",ifStatement);
printf("Number of else statements = %d\n",elseStatment);
printf("Number of for statements= %d\n",forStatement);
printf("Number of switch statements = %d\n",switchStatement);
printf("Number of semi colons = %d\n",semiColon);
printf("Number of structs = %d\n",structs);
printf("Number of arrays = %d\n",arrays);
printf("Number of blocks = %d\n",blocks);
fclose(fpointer);
return 0;
}