Keep getting a Segmentation Fault from the following.

//This program is meant to allow the user to enter up to 10 words into an array, which will then be alphabetized. The function is meant to stop taking words once ten have been entered, or when 0 is entered. At present, it compiles correctly and works fine, until it reaches the point where it is meant to sort, upon which point it stops, claiming there is a segmentation error.


#include <iostream>
#include <iomanip>
#include <cctype>
#include <cmath>
#include <cstring>
using namespace std;
cons tint NUM_WORDS = 10;
void sort(string words[], int num);

int main(void)
{
string word[NUM_WORDS];
string entered_word;
int i;
int word_count = 0;
cout << “This program will allow you to enter a series of words… \n”;
cout << “You will be allowed to enter a max of 10 words… \n”;
cout << “You can end the program at any point by entering ‘0’… \n”;
for (i=0 ; i < NUM_WORDS ; i++)
{
cout << “Enter a word: “;
cin >> entered_word;
if (entered_word == “0”)
break;
word[i]=entered_word;
word_count++;
}
sort(word, word_count);

for (i=0; I < word_count ; i++)
{
cout << word[i];
}
return 0;
}
void sort(string words[], int num)
{
int a;
int b;
string temp;
int min_index;
for (a = 0; a < (num – 1) ; a++)
{
min_index = a;
for (b = a + 1; b < num; b++)
{
if (words[b] < words[min_index])
{
min_index=b
}
}
if (a != min_index)
{
temp = words[a];
words[a] = words[min_index];
words[min_index]=temp;
}
}
}
Minus a few minor typos, this works just fine for me. Could your compiler have problems with your non-ascii characters?
Topic archived. No new replies allowed.