I am currently trying to write a program that alphabetizes strings. I have one error. It’s that minLocation does not take 2 arguments. I am fairly new to programming could anyone give me a hint as to why this part of my code is wrong?
int minLocation(string list[], int first, int last)
{
int mIndex=first;
int loc = 0;
for (loc = first+1; loc <= last; loc++)
if (list[loc] < list [mIndex])
mIndex = loc;
return mIndex;
void Sort(string slist[],int length)
{
int mIndex;
for (int loc = 0; loc < length-1; loc++)
{
mIndex = minLocation (loc,length-1);
swap (loc, minIndex);
}
}
Without seeing the definition of
minLocation, we can’t tell. But it’s a safe bet that it doesn’t take two arguments – compilers don’t lie to you just for the fun of it, you can usually assume that what they’re saying is true 🙂You need to find the definition, something like:
and figure out how you’re actually meant to call it. Given that it looks like it’s trying to find which of two indexes has the lower value, it may be that it needs more than two arguments.
And, on top of that, you need to decide whether you want that variable called
mIndexorminIndex. Most compilers aren’t quite smart enough to figure that out for you.Based on your edits that
muinFunctionis defined as:it seems evident that it also needs the string array as well as the two indexes. You will need to change the call to:
And keep an eye on the
swapcall as well. It may have a similar requirement, based on the coding style.