DISCLAIMER: 1st post, please excuse any format violations...
Good evening folks.
Here's the deal. I have seven arrays to compare and sort in alphabetical order. My problem is this...
Input
box
fat
toy
red
All three letters (individually) are being sorted, so that it would look like this...
toy
rox
fet
bad
My goal is to sort them alphabetically a------>z (as whole words).
Any suggestions? Thanks for the help!
Code:
#include<stdio.h>
#include<string.h>
#define N_STRINGS 7
#define MAX_SIZE 80
void sort(char a[][MAX_SIZE], int n);
int main(void)
{
int i, n=N_STRINGS;
char a[N_STRINGS][MAX_SIZE];
printf("Enter 7 single character strings.\n\n");
for(i=0; i<n; ++i)
scanf("%s",&a[i]);
printf("The Strings you have entered:");//print the list of string characters
for(i = 0; i<n; ++i)
printf("%s\n",&a[i]);
sort(a, n);//sort um
printf("\nThe Stings sorted are:\n");//print the list of string characters
for(i = 0; i<n; ++i)
printf("%s\n",&a[i]);
return 0;
}
void sort(char a[][MAX_SIZE], int n)
{
int i, j, k;
char temp;
for (i = 0; i < n; i++) {
for (j = i + 1; j < n; j++) {
for (k = 0; k < n; k++) {
if (strcmp(&a[j][k],&a[i][k])>0) {
temp = a[i][k];
a[i][k] = a[j][k];
a[j][k] = temp;
}
}
}
}
}