アルバムを整理して、写真だけを残します。is_jpg(file) を書きましょう。ファイル名 file が .jpg で終わるなら true、そうでなければ false を返します。小文字だけを考えます。4 文字より短い名前は必ず false です。
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;
}
実行すると例で試せます。よさそうなら提出しましょう。