I'm supposed to read all the words from text file and use bubble sort to sort the word and count their occurrence.

As I read each word from file, what is the exact thing I need to do? Do I need to store the word (as char array) somewhere to have a pointer pointing at those words? and populate the array of pointers as I read more words? I have knowledge of other language like java but I'm new to the concept of pointer. I can't find an example where I deal with actual words with pointers. I've found something with pointers and characters in a single word. I need to deal with multiple words.

while (fscanf(myfile, "%s", str) != EOF) {
//I understand str is the words that I go through
//How can I have arrays of pointers to point all the words in the text file?
//How can I dynamically populate words with pointers?

Edited by gyuunyuu: n/a

6 Years
Discussion Span
Last Post by thekashyap

Here is the pseudo-code:

// Create an array of char*(s)
// You might be forced to use a custom struct (see comments
// below) if you want to control the memory usage.
while (fscanf(myfile, "%s", str) != EOF) {
// Extract each word (find index of next white space char
// and then substring) out of str and add it into array.
// call the function that can sort this array (using bubble sort).
// loop over the array
//     count++ as long as next matches previous
//     if doesn't match print count

See these for hints on arrays.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.