By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,605 Members | 1,370 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,605 IT Pros & Developers. It's quick & easy.

Help Degugging My Program

P: 15
I am trying to write a program which sorts an array of supplied names.

These are the errors i am getting.


.cpp:39: error: expected identifier before '[' token
40: error: ISO C++ forbids declaration of `parameter' with no type
In function `void selectionSort(char*, int*, int)':
41: error: expected `;' before "counter"
44: error: `counter' was not declared in this scope
44: error: `SIZE' was not declared in this scope
45: error: `minRow' was not declared in this scope
48: error: expected `)' before "for"
48: error: `SIZE' was not declared in this scope
error: ISO C++ forbids incrementing a pointer of type `char*(*)(const char*, int) throw ()'
48: error: non-lvalue in increment
48: error: expected `;' before ')' token
52: error: expected `}' at end of input


HERE IS MY CODE

/* Matt Deshong
mgd156
Sorting by Selection
Write a program which sorts an array of supplied names (character strings).
*/

#include <iostream>
using namespace std;

const int numNames = 10;
const int nameSize = 17;
void showArray(char [],char);
void selectionSort(int [], int);
int main()
{
char names [numNames][nameSize]=
{"Collins,Bill",
"Smith,Bart",
"Allen,Jim",
"Griffin,Jim",
"Stamey,Marty",
"Rose,Geri",
"Taylor,Terri",
"Johnson,Jill",
"Allison,Jeff",
"Looney,Joe"};

showArray(names[10],numNames);

}
void showArray(char array [], char size)
{
for(int counter = 0; counter < size; counter++)
{
cout << array[counter] << endl;
}
}

void selectionSort(char array[],[nameSize],int size)
{
cin counter, minRow;
char minValue[17];

for(counter = 0; counter < (SIZE - 1); counter++)
minRow = counter;
strcpy =(minValue,array[counter]
for(int index = counter+1; index < SIZE; index++)
{ if(strcmp(array[index],minValue)<0)
strcpy(minValue,array[index]);
minRow = index;
}
Nov 11 '06 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 1,510
have a look at
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int numNames = 10;
  5. const int nameSize = 17;
  6. void showArray(char [][nameSize],char);   // ** correct array size
  7. void selectionSort(int [][nameSize], int);
  8. int main()
  9. {
  10. char names [numNames][nameSize]=
  11. {"Collins,Bill",
  12. "Smith,Bart",
  13. "Allen,Jim",
  14. "Griffin,Jim",
  15. "Stamey,Marty",
  16. "Rose,Geri",
  17. "Taylor,Terri",
  18. "Johnson,Jill",
  19. "Allison,Jeff",
  20. "Looney,Joe"};
  21.  
  22. showArray(names,numNames);
  23.  
  24. }
  25. void showArray(char array [][nameSize], char size) // ** add [nameSize]
  26. {
  27. for(int counter = 0; counter < size; counter++)
  28. {
  29. cout << array[counter] << endl;
  30. }
  31. }
  32.  
  33. void selectionSort(char array[][nameSize],int size)  // ** remove ,
  34. {
  35. int counter, minRow;     // ** int
  36. char minValue[17];
  37.  
  38. for(counter = 0; counter < (size - 1); counter++)  // ** SIZE to size
  39. minRow = counter;
  40. strcpy(minValue,array[counter]);                 // ** removed = added ); on end of line
  41. for(int index = counter+1; index < size; index++)  // ** SIZE to size
  42. { if(strcmp(array[index],minValue)<0)
  43. strcpy(minValue,array[index]);
  44. minRow = index;
  45. }
  46. }
  47.  
  48.  
Nov 11 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.