I am trying to get this problem to sort this array of names in alphabetical order, first or last name but the program has a problem with memory.
I have no errors or warnings but my program keep being aborted. The error message is this:
The instruction at "0x004053f0" referenced memory at "0x00000000". The memory could not be "read".
click ok to terminate the program or cancel to debug.
Need some help, please!!!!!!!!!
my compiler is a MS Visual C++
my os: Win2k
======================My codes below.
// Purpose of this program: This program uses the selection sort algorithm to sort
// an array of names in alphabetical order.
void showArray(char *[][2], int);
void selectionSort(char *[][2]);
#include <iostream.h>
#include <string.h>
// Function prototypes
// this code not used void selectionSort(int [], int);
// this code not used void showArray(int [], int);
void main(void)
{
char *names[20][2] = {{"Collins, Bill"},
{"Smith, Bart"},
{"Allen, Jim"},
{"Griffin, Jim"},
{"Stamey, Marty"},
{"Rose, Geri"},
{"Taylor Terri"},
{"Johnson, Jill"},
{"Allison, Jeff"},
{"Looney, Joey"},
{"Wolfe, Bill"},
{"James, Jean"},
{"Weaver, Jim"},
{"Pore, Bob"},
{"Rutherford, Greg"},
{"Javens, Renee"},
{"Harrison, Rose"},
{"Setzer, Gathy"},
{"Pike, Gordon"},
{"Holland, Beth"} };
cout << "The unsorted names are: \n\n";
showArray(names, 20);
selectionSort(names);
cout << "The sorted names are\n";
showArray(names, 20);
}
// array. elems is the number of elements in the array. *
//*********************************************************
void selectionSort(char *array[][2])
{
char sEarch[15];
int found = 0;
cout<<"\nEnter a String to sEarch : ";
cin >> sEarch;
cout << sEarch << endl;
for ( int i = 0 ; (i < 20 && !found); i++)
{
for ( int j = 0; (j < 2 && !found); j++)
{
cout<<endl << "Comparing " << array[j];
if (strcmp(sEarch,array[j])== 0)
{
found = 1;
break;
}
}
}
if (!found)
cout <<"\nString is NOT in the array!!!";
else
cout <<"\nString is in the array";
}
//**************************************************************
// Definition of function showArray. *
// This function displays the contents of array. elems is the *
// number of elements. *
//**************************************************************
void showArray(char *array[][2], int elems)
{
for (int i = 0; i < elems; i++)
{
for ( int j = 0 ; j < 2; j++)
cout << array[j]<<" ";
cout << endl;
}
cout<<endl<<endl;
}
I have no errors or warnings but my program keep being aborted. The error message is this:
The instruction at "0x004053f0" referenced memory at "0x00000000". The memory could not be "read".
click ok to terminate the program or cancel to debug.
Need some help, please!!!!!!!!!
my compiler is a MS Visual C++
my os: Win2k
======================My codes below.
// Purpose of this program: This program uses the selection sort algorithm to sort
// an array of names in alphabetical order.
void showArray(char *[][2], int);
void selectionSort(char *[][2]);
#include <iostream.h>
#include <string.h>
// Function prototypes
// this code not used void selectionSort(int [], int);
// this code not used void showArray(int [], int);
void main(void)
{
char *names[20][2] = {{"Collins, Bill"},
{"Smith, Bart"},
{"Allen, Jim"},
{"Griffin, Jim"},
{"Stamey, Marty"},
{"Rose, Geri"},
{"Taylor Terri"},
{"Johnson, Jill"},
{"Allison, Jeff"},
{"Looney, Joey"},
{"Wolfe, Bill"},
{"James, Jean"},
{"Weaver, Jim"},
{"Pore, Bob"},
{"Rutherford, Greg"},
{"Javens, Renee"},
{"Harrison, Rose"},
{"Setzer, Gathy"},
{"Pike, Gordon"},
{"Holland, Beth"} };
cout << "The unsorted names are: \n\n";
showArray(names, 20);
selectionSort(names);
cout << "The sorted names are\n";
showArray(names, 20);
}
// array. elems is the number of elements in the array. *
//*********************************************************
void selectionSort(char *array[][2])
{
char sEarch[15];
int found = 0;
cout<<"\nEnter a String to sEarch : ";
cin >> sEarch;
cout << sEarch << endl;
for ( int i = 0 ; (i < 20 && !found); i++)
{
for ( int j = 0; (j < 2 && !found); j++)
{
cout<<endl << "Comparing " << array[j];
if (strcmp(sEarch,array[j])== 0)
{
found = 1;
break;
}
}
}
if (!found)
cout <<"\nString is NOT in the array!!!";
else
cout <<"\nString is in the array";
}
//**************************************************************
// Definition of function showArray. *
// This function displays the contents of array. elems is the *
// number of elements. *
//**************************************************************
void showArray(char *array[][2], int elems)
{
for (int i = 0; i < elems; i++)
{
for ( int j = 0 ; j < 2; j++)
cout << array[j]<<" ";
cout << endl;
}
cout<<endl<<endl;
}