I need to write a program that counts up all the semicolons in a function within a file...
I know the algorithm but i'm having trouble putting into code...
What i'm trying to do right now is search through the file for the string "FUNCTION" (which is included in the file to designate the start of the function)
Is this the proper way to do it? or should I use a strcmp function? I get one error from this and it says "too many characters in constant" at the if (str== START) line
Also, if there is no "FUNCTION", how do I proceed to the next line of the file to check again?
#include <stdio.h>
#include <string.h>
#define START 'FUNCTION'
int main(void)
{
FILE *fp;
char str[100], fileName[100];
printf("Enter file name: ");
gets(fileName);
fp = fopen(fileName, "r");
if (fp==NULL)
{
printf("%s can not be opened.\n", fileName);
}
fgets(str, sizeof(str), fp);
if (str == START)
{
printf("There is a function.");
}
}