#include <stdio.h>
#include <string.h>
#define MAX_ROWS 5
#define MAX_COLS 10
void swapStrings(char str1, char str2) {
char temp[MAX_COLS];
strcpy(temp, str1);
strcpy(str1, str2);
strcpy(str2, temp);
}
void sort2DArrayByStringLength(char arr[MAX_ROWS][MAX_COLS], int rows) {
for (int i = 0; i < rows - 1; ++i) {
for (int j = 0; j < rows - i - 1; ++j) {
if (strlen(arr[j]) > strlen(arr[j + 1])) {
swapStrings(arr[j], arr[j + 1]);
}
}
}
}
int main() {
char strings[MAX_ROWS][MAX_COLS] = {"apple", "banana", "orange", "grape", "kiwi"};
sort2DArrayByStringLength(strings, MAX_ROWS);
printf("Sorted 2D Array by String Length:\n");
for (int i = 0; i < MAX_ROWS; ++i) {
printf("%s\n", strings[i]);
}
return 0;
}