Ok this code is just like the code before, but it shows the exact problem, it will compile fine, no errors, no warnings, but when it runs it just gets a "Segmentation Fault", and outputs nothing, but if I // remark out the qsort( funtion line, it compiles fine, and outputs perfectly, albeit unsorted.
Any help, ideas, again, im using linux and gcc.
gcc -g -Wall -I../../../include test.c -o test
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
char tstring[256];
char tgot[256];
char tname[256];
char tdata[50000][256];
int tfi=0;
int i=0;
DIR *pd;
struct dirent *allp;
static int scomp(const void *p1, const void *p2)
{
char *a = * (char **) p1;
char *b = * (char **) p2;
return strcasecmp(a,b);
}
int main()
{
pd = opendir ("/mnt/winc/Music"
if ( pd != NULL ) {
while ( (allp = readdir(pd)) ) {
sprintf(tstring,"%s",allp->d_name);
strcpy(tgot,tstring);
strcpy(tname,(&tgot[0]));
sprintf(tdata[tfi],"%s",tname);
tfi++;
}
}
tfi=tfi-1;
closedir(pd);
qsort(tdata, tfi, sizeof tdata[0], scomp);
i=0;
do {
printf("%s\n",tdata);
i++;
}while (i<tfi);
printf("%d\n",i);
return 0;
}
Any help, ideas, again, im using linux and gcc.
gcc -g -Wall -I../../../include test.c -o test
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
char tstring[256];
char tgot[256];
char tname[256];
char tdata[50000][256];
int tfi=0;
int i=0;
DIR *pd;
struct dirent *allp;
static int scomp(const void *p1, const void *p2)
{
char *a = * (char **) p1;
char *b = * (char **) p2;
return strcasecmp(a,b);
}
int main()
{
pd = opendir ("/mnt/winc/Music"
if ( pd != NULL ) {
while ( (allp = readdir(pd)) ) {
sprintf(tstring,"%s",allp->d_name);
strcpy(tgot,tstring);
strcpy(tname,(&tgot[0]));
sprintf(tdata[tfi],"%s",tname);
tfi++;
}
}
tfi=tfi-1;
closedir(pd);
qsort(tdata, tfi, sizeof tdata[0], scomp);
i=0;
do {
printf("%s\n",tdata);
i++;
}while (i<tfi);
printf("%d\n",i);
return 0;
}