Untitled

 avatar
unknown
c_cpp
2 months ago
607 B
2
Indexable
#include <stdio.h>
#include <string.h>

int main() {
    char names[][2][50] = { 
        {"John", "Doe"}, 
        {"", "Smith"}, 
        {"Alice", "Brown"},
        {"", "Johnson"},
        {"Michael", "Clark"}
    };

    int n = sizeof(names) / sizeof(names[0]); // Get the number of entries

    for (int i = 0; i < n; i++) {
        if (strlen(names[i][0]) > 0) {
            printf("%s\n", names[i][0]); // Print first name if it's not empty
        } else {
            printf("%s\n", names[i][1]); // Print last name if first name is empty
        }
    }

    return 0;
}
Editor is loading...
Leave a Comment