I want to input some strings and sort them alphabetically, at most 100 strings and the length of each string is less than 50, but I get a Segmentation fault.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int comp(const void * a, const void * b)
{
return strcmp (*(const char **) a, *(const char **) b);
}
int main()
{
char sequences[100][50];
int nr_of_strings;
scanf("%d", &nr_of_strings);
int i;
for(i = 0; i < nr_of_strings; ++i)
scanf("%s", sequences[i]);
qsort(sequences, nr_of_strings, sizeof(char *), comp);
for(i = 0; i < nr_of_strings; ++i)
printf("%s\n", sequences[i]);
}
compfunction, before you callstrcmp, try to print the arguments, to see if they really are what you think they are. Or use a debugger.char *for each string.