![]() |
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?
:
|
Could you post all of the code you have so far? :)
btw...I love strawberries |
1 Attachment(s)
Yeah, but I think I'm going about this all wrong. Right now it's just reading then printing the first 10 words. But I need to store them. But every time I use something like temp[a] = strtok( Buffer, delimiters) or something it messes up completely. How can I store each of the words?
:
Also I attached the words_emancip.txt file, just in case you want to run it. |
Ok I thought maybe I messed up by putting
:
token = strtok(Buffer, delimiters);:
strcpy( token, strtok(Buffer, delimiters) |
Sorry I don't know exactly what you want, but I modied your code a bit to make it shorter.
This will store 10 words in a 2D character array and output them aswell :
#include <stdio.h> |
Thanks, that is a lot cleaner looking. But what I need to ultimately do is store all of the words. Well here's the instructions:
:
Maybe that will help. So what I need to do is store every word and a count of how many times it appears in a parallel array, that way I can sort them later and print the first and last 10 again. |
Here's my professor's sample output.
:
Select a file by number from this list: |
Ok new question. Disregard previous questions. How do I get it to print the last 10 words of the file? And it won't even give me the first 10 words of files 2-5. It only works for words_emancip.txt
|
last ten words of a file? I would read all the words and create a list with the following structor
struct member { char word[80]; int place; struct word *next; } then count them and print the last ten.If you want more info on how to use this pm. You can even use this to put them in alphabetical order. |
| All times are GMT -5. The time now is 2:03 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC