sort string array in c, but program crashes : <p>I'm looping through a file to find matching records for a user input, then I need to print them in an ascending order. My program keeps crashing. I need help please. I've written a few functions to do the work.</p>

<pre><code>static int myCompare (const void * a, const void * b)
{
    return strcmp (*(const char **) a, *(const char **) b);
}

void sort(const char *arr[], int n)
{
    qsort (arr, n, sizeof (const char *), myCompare);
}

void search_contact() {
    FILE * fp;
    bool found = false;
    char *records;
    fp = fopen("contact.txt", "r");
    system("cls");
    printf("\t*****SEARCH CONTACT*****");
    printf("\n\t Enter Mobile: ");
    char mobile[20];
    scanf("%s", mobile);
    char mobile1[20], name[20];    
    while (fscanf(fp, "%s %s", name, mobile1) != EOF) {
        if (strcmp(mobile, mobile1) == 0) {
            records = malloc(sizeof(name));
            strcpy(records,name);

            int i;
        //  printf(" %s", records);
            found = true;
        } else {
            found = false;
        }
    }
    if(found){
        int n = sizeof(records)/sizeof(records[0]);
         sort(records, n);
         int i;
         for (i = 0; i &lt; n; i++)
            printf("%s \n", records[i]);
    }
    else{
        printf("\n No Records Found!");
    }
    fclose(fp);
    printf("\n\tPRESS ANY KEY TO CONTINUE");
    getch();
    main();
}
</code></pre>
