#include <stdio.h>
#include <string.h>
int main(void)
{
const char words[6][20] = { "stripos", "click", "substr", "save", "search", "sizeof" };
char *p = NULL;
char line[256], file[20] = "d:\\url.php";
int count[6] = { 0 };
FILE *fp;
int i;
if ( !(fp = fopen(file, "r")) )
{
printf("Error open file: %s", file);
return 1;
}
while (fgets(line, sizeof(line), fp))
for (i = 0, p = line; i < 6; i++, p = line)
while ( (p = strstr(p, words[i])) )
{
p = p + strlen(words[i]);
count[i]++;
}
fclose(fp);
for (i = 0; i < 6; i++)
printf("The word: %-10s appear %3d times in file: %s\n", words[i], count[i], file);
return 0;
}
/*
run:
The word: stripos appear 5 times in file: d:\url.php
The word: click appear 50 times in file: d:\url.php
The word: substr appear 14 times in file: d:\url.php
The word: save appear 4 times in file: d:\url.php
The word: search appear 7 times in file: d:\url.php
The word: sizeof appear 2 times in file: d:\url.php
*/