Hi, I can't seem to get my program to work. I'm using qsort to sort some keyboard-input strings, but I get segmentation fault. I tried 3 versons, and none of them works. Could someone pinpoint the error?
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<search.h>
int str_cmp(const void *prv,const void *vtor);
main()
{
int m,j;
char strings[10][10];
scanf("%d",&m);
for(j=0;j<m;j++)
scanf("%s",&strings[j]);
qsort(strings,m,sizeof(char *),str_cmp);
return 0;
}
int str_cmp(const void *prv,const void *vtor)
{
return (strcmp(*(const char **)prv, *(const char **)vtor));
}
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<search.h>
int str_cmp(const void *prv,const void *vtor);
main()
{
int m,j;
char *strings[10];
scanf("%d",&m);
for(j=0;j<m;j++)
scanf("%s",&strings[j]);
qsort(strings,m,sizeof(char *),str_cmp);
return 0;
}
int str_cmp(const void *prv,const void *vtor)
{
return (strcmp(*(const char **)prv, *(const char **)vtor));
}
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<search.h>
int str_cmp(const void *prv,const void *vtor);
main()
{
int m,j;
char strings[10][10];
char **pok;
*pok=*strings;
scanf("%d",&m);
for(j=0;j<m;j++)
scanf("%s",&strings[j]);
qsort((void *)pok,m,sizeof(char *),str_cmp);
return 0;
}
int str_cmp(const void *prv,const void *vtor)
{
return (strcmp(*(const char **)prv, *(const char **)vtor));
}