So, I've written this code below that is supposed to pass an array of strings to a function, which then sorts the array into alphabetical order. I know the way I've done it probably isn't pretty, but it is for school and I'm required to pass it to a function and make use of strcmp. I ran into some problems, but I managed to get all the compile errors sorted. Now, however, when I try to run the program, I get the error segmentation fault(core dumped). Can someone guide me to where I made my mistake?
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
void sort(char *str[]);
int main()
{
char *states[11] = {"Florida", "Oregon", "California", "Georgia"};
sort(states);
return 0;
}
void sort(char *str[])
{
int x, y;
char alpha[11] = {0};
for(x = 1; x < 4; x++){
for(y = 1; y < 4; y++){
if(strcmp(str[y - 1], str[y]) > 0){
strcpy(alpha, str[y - 1]);
strcpy(str[y - 1], str[y]);
strcpy(str[y], alpha);
}
}
}
printf("\nThe states, in order, are: ");
for(x = 0; x < 4; x++)
printf("\n%s", str[x]);
}