lexicographic order!

Hi guys. Ok so i have the following problem. I want to implement a lexicographical order of some characters entered from the keyboard. when i press "n" i want it to return the order. Ignore the part with "insert a specific number of words" that's for smthn else. i hope you understand me :(

#include <iostream>
#include <string.h>
using namespace std;


int main ()
{
int n, i, j;
char oprire, decizie, v[20], x[100][20];
cout<<"\t""welcome!""\n";
cout<<"\n""the next programs sorts word lexicographically""\n";
cout<<"\n""if you wish to insert a specific number of words press 'Y'""\n";
cout<<"\n""if you wish to insert words undefinetely press 'N'""\n";
cout<<"\n";
cin>>decizie;
if(decizie == 'n' || decizie == 'N')
{
for (i=1; i<=100; i++)
{
cout<<"\n""Insert word " <<i<<" : ";
cin>>x[i];
cout<<"Want more words?(y/n)""\n";
cin>>oprire;
if (oprire == 'y') continue;
else if(oprire=='n')
{
for (i=1;i<=100;i++)
for (j=i + 1;j <= 100;j++)
if (strcmp(x[i],x[j]) > 0)
{
strcpy(v,x[i]);
strcpy(x[i],x[j]);
strcpy(x[j],v);
}
cout<<"\n""The word in lexicographic order are: ""\n";
cout<<"\n";
for (i = 1 ; i <= 100 ; ++i)
cout<<"\n" <<i <<". " << x[i] << '\n';
}
}
return 0;
}
}



it keeps giving me returned error code -1073741819
Last edited on
Array indices start at 0.

There are several problems.

First off your program flow is wrong, your first for..loop to loop and get words will continue to loop once the user hits n to run the bubble sort and list alphabetical.

Regardless if I was to enter three words, you cycle through each element of your array (all 100 of them) which contain garbage - count the number of words entered and sort those.

Arrays start at 0, not 1 and a array of size 100 has available elements 0-99, not 1-100.

Topic archived. No new replies allowed.