View Single Post
Old Apr 2nd, 2005, 12:12 PM   #1
mmmm_strawberries
Newbie
 
Join Date: Feb 2005
Posts: 10
Rep Power: 0 mmmm_strawberries is on a distinguished road
Send a message via AIM to mmmm_strawberries
Help with sorting and counting?

Well, so far I have this program reading the first 10 words of a file. But what I need it to do is read all of the words, sort the words, count the words, and print the first and last 10 words of the unsorted, then read the first and last 10 words of the sorted. So as you can see I'm so far away. But what I need help with right now is sorting all the words. Here's the fragment of my code that reads from the file. Any suggestions?


if( myfile != NULL)
{

	for(a=0; a<10; a++)
	{
		/* Get one line */
		fgets(Buffer, 5000, myfile);
		if (!feof(myfile))
		{
			/* Break the line up into words */
			token = strtok(Buffer, delimiters);
			while (token != NULL)
			{
				puts(token);
						
				/* Get the next word */
				token = strtok(NULL, delimiters);
			}
		}
	}
	   	fclose( myfile );
}
mmmm_strawberries is offline   Reply With Quote