整理相簿,只留照片。寫 is_jpg(file):檔名 file 以 .jpg 結尾就返回 true,否則 false。只認小寫;比 4 個字元還短的名字一定不是。
is_jpg("beach.jpg")→Trueis_jpg("notes.txt")→Falsebool is_jpg(const char *file)#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;
}
寫好了先點「執行」試試示例,沒問題再點「提交」。