Kodewick
开始学 →
基础←→0 / 70

是照片吗

#042基础字符串条件约 5 分钟

整理相册,只留照片。写 is_jpg(file):文件名 file 以 .jpg 结尾就返回 true,否则 false。只认小写;比 4 个字符还短的名字一定不是。

示例
is_jpg("beach.jpg")→True
is_jpg("notes.txt")→False
函数bool 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) {
        // 在这里写:从倒数第 4 个字符开始,和 ".jpg" 比
    }
    return ok;
}
Ctrl + Enter 也能运行
结果

写好了先点「运行」试试示例,没问题再点「提交」。