Not one of my C books teaches me this, but can I ask... as I have to specify the array size and the length of the string, do I use a 2 dimensional array to input sort and output the strings?
I assume I cannot use a single one as all I can do with that is speicfy the array size.
I had a quick mess around with a one dimensional without the sort method and im already running into problems with a seg fault as I havent specified the size. I also find it incredible that my book expects me to know how to do this when not once did it mention sorting string-type arrays, only integer and float using bubble and selection sort.
Code:
#include <stdio.h>
#define ARRAY_SIZE 3
/*main function - begins program execution -----------------------------------*/
int main ( void )
{
char names[ ARRAY_SIZE ];
int i;
printf("Enter three names: ");
for ( i = 0; i < ARRAY_SIZE; i++ )
{
scanf("%30s", &names[ i ]);
}
printf("\n\nYou entered\n\n");
for ( i = 0; i < ARRAY_SIZE; i++ )
{
printf("%c\n", names[ i ]);
}
getchar(); /*freeze console output window*/
return 0; /*return value from int main*/
}