Does this make any sense?
hey I made a program that should find how many times a certain string appears in a .txt file does this code make sense as I said before, and if you find errors please point them out. Thanks
Code:
#include <stdio.h>
#include <string.h>
int searchnum = 0;
char getline[1000];
char line[1000];
char lineh;
int find(FILE *pfile);
main()
{
char search[20];
strcpy(search,"hi");
FILE *pfile;
pfile = fopen("searchfile.txt","r");
printf("searchtext: %s ",search);
if (pfile == NULL)
{
printf("file does not exist, you fail");
getch();
}
else{
while(fputc(lineh,pfile) != EOF)
{
if (lineh == '\0')
{
if (line == search)
{
searchnum + 1;
printf("found %d\n",searchnum);
}
}
else
{
printf("%c\n",lineh);
strcat(lineh,line);
}
}
printf("%d",searchnum);
getch();
}
}
hope you can help