Hey everybody, i understand that obviously this isnt a place to get your homework done and ive read the thread about it too.
Im currently doing a uni course with some basic C, but abit of it is going over my head -
my task so far has been to write a program that calculates the number of words in a text file. and ive managed this ok...
Code:
/* Document Analyser
Author - JJ Singer
Version 1.0
Bulid Date - 02/12/04
A program that asks the user for the name
of a text file to read, reads it and counts
the number of words in the file. It then
will display this number to the user */
#include <stdio.h> //includes input/output command library
void main ()
{ // VARIABLES DEFINED
int counter, fileend;
// counter: stores the number of words in the file,
// fileend: tells the program when the file has ended
char content[300], filename[10];
// content: tells the program the length of the field to expect and its type
// filename: tells the program the length of the field to expect and its type
FILE *filein;
// give the program a file pointer to the filein stream
printf("***************************\n");
printf("* *\n");
printf("* DOCUMENT ANALYSER *\n");
printf("* Author - JJ Singer *\n");
printf("* Version 1.0 *\n");
printf("* Build Date - 02/12/04 *\n");
printf("* *\n");
printf("***************************\n\n\n");
//header
printf ("Please type in the name of the file you wish to read and press enter\n\n");
//dispays the prompt on screen
scanf ("%s",filename);
// makes the program read the text entered (specifically the file name)
filein=fopen(filename,"r");
//opens the file stream of the required file
fileend=fscanf(filein, "%s",content);
// assigns the integer value of true of false (1/0) to the fileend variable
while(fileend!=EOF) // loop - counts the number of words in the file
// while the end of the file is not reached
{
counter++;
fileend=fscanf(filein,"%s",content);
}
printf("Analysing document..................\n\n\n");
printf("This file contains %d words\n\n",counter);
// displays the word count on screen
fclose(filein);
// closes the file stream
}
the part i am having problems with is part of the next task which builds on the current code - im required to count the number of UNIQUE words in the text file and give a total of these.
I think the way i should do this is -
using for loops (possibly 2?) and compare two strings (strcmp function) and a counter that increases by one each time non unique words are found. Then by calculating the difference between the unique total and (general) total.
however, im not sure where or how to implement this section.. as i say, its going over my head a little bit.
could anyone put some light on this matter for me?
PS (heard i might need to use a "to lower / to upper " function.. however this may be some variable instead.. not sure)
cheers for any help.
Josh.