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?
}

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.
http://cboard.cprogramming.com/c-programming/104527-using-realloc-dynamically-growing-array.html
http://stackoverflow.com/questions/3536153/c-dynamically-growing-array

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.