Im currently trying to make a program that will count various parameters of other c programs.
My program is fundementally flawed somehow. The program keeps re-entering the countWhiles() function for some reason, and then throughs up a Access violation.
Ive stripped everything else out of the program.
Does anyone know whats going wrong?
My program is fundementally flawed somehow. The program keeps re-entering the countWhiles() function for some reason, and then throughs up a Access violation.
Ive stripped everything else out of the program.
Does anyone know whats going wrong?
Code:
#include <stdio.h>
#include <string.h>
FILE *pInput;
void countWhiles(void);
int main()
{
/* open the file to be read */
pInput = fopen("1.c", "r");
countWhiles();
exit(0);
}
void countWhiles()
{
char str[] ="";
int count = 0;
while (!feof(pInput))
{
fscanf (pInput, "%s", str);
if (strcmp( str, "/*") == 0)
{
while(!(strcmp( str, "*/") == 0))
fscanf (pInput, "%s", str);
}
else if(strcmp( str, "while" ) == 0)
count++;
}
rewind(pInput);
/* output the results */
printf("The program contains: %d while statments\n",count);
}