[Solved] How to sort structs from least to greatest in C?


fix like this

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define BUFF_SIZE 32
#define STRUCT_SIZE 512

struct info {
    char name[BUFF_SIZE];
    char stAddress[BUFF_SIZE];
    char cityAndState[BUFF_SIZE]; 
    char zip[BUFF_SIZE];
};

void selectionSort(struct info *ptrStruct[], int size);//!

int main(void){
    int count, size;//!
    char buffer[600];
    struct info *ptrStruct[STRUCT_SIZE];

    for (count = 0; count < STRUCT_SIZE; count++){
        ptrStruct[count] = (struct info*) malloc(sizeof(struct info));
        if(EOF==scanf("%599[^\n]%*c", buffer)){//!
            free(ptrStruct[count]);
            break;
        };
        strcpy(ptrStruct[count]->name, buffer);
        scanf("%599[^\n]%*c", buffer);
        strcpy(ptrStruct[count]->stAddress, buffer);
        scanf("%599[^\n]%*c", buffer);
        strcpy(ptrStruct[count]->cityAndState, buffer);
        scanf("%599[^\n]%*c", buffer);
        strcpy(ptrStruct[count]->zip, buffer);
    }

    size = count;//!
    selectionSort(ptrStruct, size);//!

    printf("\n\nLEAST TO GREATEST\n");
    for (count = 0; count < size; count++)//!
    {
        printf("%s\n", ptrStruct[count]->name);
        printf("%s\n", ptrStruct[count]->stAddress);
        printf("%s\n", ptrStruct[count]->cityAndState);
        printf("%s\n", ptrStruct[count]->zip);
        free(ptrStruct[count]);
    }
}

void selectionSort(struct info *ptrStruct[], int size)//!
{
    int count1, count2;
    int minIndex;
    struct info *ptrTemporary;

    for (count2 = 0; count2 < size -1; count2++)//!
    {
        minIndex = count2;
        for (count1 = count2 + 1; count1 < size; count1++)//!
        {
            if (strcmp(ptrStruct[count1]->zip, ptrStruct[minIndex]->zip) < 0)//!
                minIndex = count1;
        }
        if(minIndex != count2){
            ptrTemporary = ptrStruct[count2];//!
            ptrStruct[count2] = ptrStruct[minIndex];
            ptrStruct[minIndex] = ptrTemporary;//!
        }
    }
}

2

solved How to sort structs from least to greatest in C?