#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int i,j;
char temp[10];
char **A;
A=(char**)malloc(10*sizeof(char*));
for(i=0;i<10;i++)
A[i]=(char*)malloc(100*sizeof(char));
printf("Enter the words you would like to sort :\n");
for(i=0;i<10;i++)
gets( *A );
for(i=0; i < 10 ; i++)
{
{
if(strcmp(A[i],A[i+1]) > 0)
{
strcpy(temp,A[i]);
strcpy(A[i],A[i+1]);
strcpy(A[i+1],temp);
}
}
}
for (i = 0; i < 10; i++)
printf("%s\n", A[i]);
return 0;
}
I am trying to write a C program that sorts a given list of 10 strings in alphabetical order. The program takes all of the strings but then it freezes and doesn't sort them. Can anyone tell me where I am going wrong? Thank you in advance.
gets( *A ), do you meangets( A[i] )?if(strcmp(A[i],A[i+1]) > 0):a[i+1]out of bounds wheniis 9.