Kodewick
Start learning →
Basic←→0 / 70

Is it a photo?

#042BasicStringsConditions5 min

Sorting the album, only photos stay. Write is_jpg(file): return true if the name file ends with .jpg, otherwise false. Lower case only; a name shorter than 4 characters never is.

Examples
is_jpg("beach.jpg")→True
is_jpg("notes.txt")→False
The functionbool is_jpg(const char *file)
main.c
#include <stdbool.h>
#include <string.h>

bool is_jpg(const char *file) {
    bool ok = false;
    int len = strlen(file);
    if (len >= 4) {
        // your code here: compare ".jpg" with the string from the 4th character from the end
    }
    return ok;
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.