Thank you I got it to work in a different way but now I am having another problem with this program.
Here is what is supposed to happen with this program.
Use the bubble sort program given in the textbook as a starting point. Rewrite this program to sort an array of “strings” rather than an array of integers.
Write a program that will do the following:
1.) Prompt the user for words and store these words in an array.
2.) Print the words in the array after it is loaded.
3.) Sort the words in the array so that they are in alphabetical order.
4.) Print the words in the array after the sort is completed.
Your program should allow for the possible storage of up to 25 words. Each word should allow a maximum size of 15 letters. Your program should make certain that these limits are not exceeded so that the program does not crash if more words, or longer words, are entered by the user.
A sample run is shown below.
Sample Run
Enter a word: four
Do you have more words? yes or no: y
Enter a word: score
Do you have more words? yes or no: y
Enter a word: and
Do you have more words? yes or no: y
Enter a word: seven
Do you have more words? yes or no: y
Enter a word: years
Do you have more words? yes or no: y
Enter a word: ago
Do you have more words? yes or no: n
four
score
and
seven
years
ago
ago
and
four
score
seven
years
Here is what I got so far
CODE
#include <stdio.h>
#include <string.h>
#define MAX_WORDS 25
#define MAX_LENGTH 15
char repeat[4];
int main(void)
{
int i;
int hold;
int pass;
int numWords;
char words[MAX_WORDS];
printf("Do you have a word y or n: ");
scanf("%s", repeat);
numWords = 0;
while (repeat[0] == 'y')
{
printf("Enter a word: ");
scanf("%s",&words);
printf("Do you have another word y or n: ");
scanf("%s", repeat);
numWords++;
}
for(i = 0; i < numWords; i++)
printf("%s\n", words[i]);
/*bubble sort*/
for(pass = 0; pass < numWords; pass++)
{
for(i = 0; i < numWords; i++)
{
if(words[i] > words[i + 1])
{
hold = words[i];
words[i] = words[i + 1];
words[i + 1] = hold;
}
}
}
getchar();
getchar();
return 0;
}