Background - Am trying to allocate a file a number of points depending on how relavent it it to a word entered by a user. At present the program finds which line the word occurs on and also how many lines there are in the file.
Aim - To divide the program up into 10 sections (ie. divide linepoint by 10) and allocate 100 points for each time the word occurs in the first 10% of the code and then 90 points for each time the word occurs in the first 20% of the code and so on.
At present am having problems as was trying to say:
if ((strstr (pointstemp, pointsword))==((linepoint/100)*10))
but threw up warnings are i was trying to compare a char and an int and so was not working effectively.
Any ideas would be greatly appreciated as am having serious problems with this. Thanks very much in advance.
My code so far is...
printf("Please enter file name: ");
printf("Please enter word: ");
if ((pp = fopen(pointsfilename, "r")) == NULL)
while( fgets(pointstemp, 256, pp) != NULL)
if ((strstr(pointstemp, pointsword)) !=NULL)
printf("Line number containing %s is %d\n", pointsword, linepoint);
printf("Number of lines is %d\n", linepoint);
if (findpoint == 0)
printf("\nNo match found.\n");
The function points() needs to be of a certain type, for example:
You cannot use function points like this:
If you want to pass that value to points, then to this as follows:
Declare function as: int points (int p);
Use function as: points (100);
Also function points() seems to return an error value, it would be recommendable to check this value. Like:
result = points (100);
if (result == -1)
/* do some error handling */
If you open a file using fopen(), then you must close it when you are done with the file using fclose().
Thanks very much for your help, have got the code working now.