Help Degugging My Program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • k1ckthem1dget
    New Member
    • Nov 2006
    • 15

    Help Degugging My Program

    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(c har*, 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(i nt [], int);
    int main()
    {
    char names [numNames][nameSize]=
    {"Collins,Bill" ,
    "Smith,Bart ",
    "Allen,Jim" ,
    "Griffin,Ji m",
    "Stamey,Mar ty",
    "Rose,Geri" ,
    "Taylor,Ter ri",
    "Johnson,Ji ll",
    "Allison,Je ff",
    "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(c har array[],[nameSize],int size)
    {
    cin counter, minRow;
    char minValue[17];

    for(counter = 0; counter < (SIZE - 1); counter++)
    minRow = counter;
    strcpy =(minValue,arra y[counter]
    for(int index = counter+1; index < SIZE; index++)
    { if(strcmp(array[index],minValue)<0)
    strcpy(minValue ,array[index]);
    minRow = index;
    }
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    have a look at
    Code:
    #include <iostream>
    using namespace std;
    
    const int numNames = 10;
    const int nameSize = 17;
    void showArray(char [][nameSize],char);   // ** correct array size
    void selectionSort(int [][nameSize], 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,numNames);
    
    }
    void showArray(char array [][nameSize], char size) // ** add [nameSize]
    {
    for(int counter = 0; counter < size; counter++)
    {
    cout << array[counter] << endl;
    }
    }
    
    void selectionSort(char array[][nameSize],int size)  // ** remove ,
    {
    int counter, minRow;     // ** int
    char minValue[17];
    
    for(counter = 0; counter < (size - 1); counter++)  // ** SIZE to size
    minRow = counter;
    strcpy(minValue,array[counter]);                 // ** removed = added ); on end of line
    for(int index = counter+1; index < size; index++)  // ** SIZE to size
    { if(strcmp(array[index],minValue)<0)
    strcpy(minValue,array[index]);
    minRow = index;
    }
    }

    Comment

    Working...