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

#define MAX_LENGTH 50

void getInput(char inputArr[][MAX_LENGTH], int inputSize);
void bubbleSort(char inputArr[][MAX_LENGTH], int inputSize);

int main() {
    int size = 3;
    char array1[size][MAX_LENGTH];

    getInput(array1, size);

    printf("original array: \n");
    for(int i = 0; i < size; i++){
        printf("%s\n", array1[i]);
    }

    bubbleSort(array1, size);

    printf("\nsorted array: \n");
    for(int i = 0; i < size; i++){
        printf("%s\n", array1[i]);
    }
    return 0;
}

void getInput(char inputArr[][MAX_LENGTH], int inputSize){
    for(int i = 0; i < inputSize; i++)
    {   
        fgets(inputArr[i], MAX_LENGTH, stdin);
        inputArr[i][strcspn(inputArr[i], "\n")] = '\0';
    }
}


void bubbleSort(char inputArr[][MAX_LENGTH], int inputSize){
    char temp[MAX_LENGTH];
    for(int i = 0; i < inputSize - 1; i++)
    {
        for(int j = 0; j < inputSize - 1 - i; j++){
            if(strncmp(inputArr[j], inputArr[j+1], 1) > 0){
                strcpy(temp, inputArr[j]);
                strcpy(inputArr[j], inputArr[j+1]);
                strcpy(inputArr[j+1], temp);
            }
        }
    }

}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: