Hi,
THis is a program which alphabetizes a list of strings using bubblesort. But theres only one compile error: variable-sized may not be initialized. BUt it's already been initialized. Pls help, other than this the problem worked fine.
THnx
Code:
#include <stdio.h>
#include <string.h>
void bubbleSort_strings( char *a[], int size );
int main()
{
int i, size = 4;
char *strings[ size ] = { "ABC", "BCD", "CDE", "DEF" };
bubbleSort_strings( strings, size );
printf( "Sorted list of strings are: \n" );
for ( i = 0; i < size; i++ )
printf( "%s ", strings[ i ] );
system( "PAUSE" );
return 0;
}
void bubbleSort_strings( char *a[], int size )
{
int pass, j;
char hold[ 100 ];
for ( pass = 1; pass <= size - 1; pass++ )
for ( j = 0; j <= size - 2; j++ )
if ( strcmp( a[ j ], a[ j + 1 ] ) == 1 ) {
strcpy( hold, a[ j ] );
strcpy( a[ j ], a[ j + 1 ] );
strcpy( a[ j + 1 ], hold );
}
}