If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

record is a pointer to a pointer (**record), used like a dynamic array and numwords is the number of words/records.

This is homework. I'm supposed to read in a text file, read out a text file with all the lines a certain size or less, and read out a sorted text file that has one occurrence of each word (without worrying about punctuation) and the number of times that word occurred.

Everything but the sorted part is done, I just can't seem to get the qsort function to work right.

Re: qsort help

Also on a side note: what exactly does "warning: implicit declaration of function ‘strdup’ " mean?

From what I've been able to find that warning says something along the lines of not having the right header file imported.

When you write a 'C' program, you need not declare your functions. The problem with this is that if you do not declare your functions, the compiler will use as the default return type "int".

That is why when you post 'C' code, you need to post all of the code, including all the headers. For example, there is a huge difference in this C program if the header is not included:

Code:

int main()
{
double x = sqrt(10);
}

Code:

#include <math.h>
int main()
{
double x = sqrt(10);
}

You say "what makes this different"? The answer is the header file <math.h>. When math.h is not included, the compiler assumes that sqrt() is a function returning an int. But in reality, the function returns a double. What can happen? A crash due to a corrupt stack.

The <math.h> declares the sqrt() function as returning a double and taking a double as the argument. This forces the 'C' compiler to do the compile check to make sure 1) the correct object code is generated with respect to the return type of double, and 2) the arguments you're passing are the right type and the right number.

For example, this program compiles just fine:

Code:

int main()
{
double x = sqrt(10, 3, 5, 5);
}

What happens when you run it? Who knows.

That's why when 'C' was first developed, these errors existed all over the place in practically every non-trivial app. That's why function prototypes made it into 'C' in a later revision of the language (but still not mandatory) -- the bugs were literally making 'C' programmers have sleepless nights.

However, for C++, it is a requirement that all functions are declared and/or defined before you call them. You can't make this mistake in a C++ program.