Hi,
I've been working on the code below for some time now and I just can't fix it,
can some one please help me.
basically I want to get an input file and a search word as command line arguments and I want to output the number of occurrence of that word in the file.
Code:
#include <stdio.h>
#include <ctype.h>
#include <stdafx.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
int _tmain(int argc, _TCHAR* argv[])
{
char buff[1000]={0},
tempStr[300]={0},
*tokenPtr;
int i=0;
int n = 0;
int j =0;
if ( argc > 2 ) {
FILE *fp = fopen( argv[1], "r" );
if ( fp == NULL ) perror ("error openning file");
else {
while ( fgets( tempStr, sizeof tempStr, fp ) != NULL ) {
strcat(buff,tempStr);
}
tokenPtr = strtok (buff,",. \n\t!-");
while (tokenPtr != NULL) {
for (i=2;i<3;i++) {
if (strcmp (tokenPtr,argv[i]) == 0) {
n++;
}
tokenPtr = strtok (NULL,",. \n\t!-");
}
printf( "%8s%15s\n", "Search Word ", "Occurrences" );
printf( "%4s%15d", argv[i],n, '\n' );
printf( "\n" );
getchar();
fclose (fp);
}
}
return 0;
}
it gives me this error when try to compile it:
fatal error C1075: end of file found before the left brace '{' at 'myprog4.cpp(10)' was matched