文字列に大文字が含まれているかどうか確認するプログラムを作りました。実行結果は期待どおりになったのですが、ソースファイルの中身がイマイチです。
![](/wp-content/include/images/avatar/teacher/5.png)
どこが手直しできそうか、分かりますか?
main.c
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int SearchUpper(const char *pText) {
const char *p = pText;
while (*p != '\0') {
if (isupper(*p)) {
return 1;
}
p += 1;
}
return 0;
}
int main(void) {
const char *pName = "Leo";
if (SearchUpper(pName)) {
printf("%s contains uppercase.\n", pName);
}
return EXIT_SUCCESS;
}
実行結果
Leo contains uppercase.
![](/wp-content/include/images/avatar/student/6.png)
これは、僕の名前(
"Leo"
)には大文字が含まれているっていう実行結果ですね。
![](/wp-content/include/images/avatar/teacher/3.png)
そうね。じゃあ、ソースファイルの中身を解読してみましょうか。
![](/wp-content/include/images/avatar/student/7.png)
はい。
SearchUpper()
っていうのは、大文字を検索する関数ですかね。
![](/wp-content/include/images/avatar/teacher/2.png)
うんうん、それから?
![](/wp-content/include/images/avatar/student/6.png)
えっと……大文字があったら1を返して、なかったら0を返すようになってます。
![](/wp-content/include/images/avatar/teacher/4.png)
正解よ!
![](/wp-content/include/images/avatar/student/4.png)
やったー。
![](/wp-content/include/images/avatar/teacher/5.png)
それじゃあ、今の説明の中で、ちょっとモヤモヤする部分がなかったかしら?
![](/wp-content/include/images/avatar/student/12.png)
そうですね……。正直「なんか変だぞ」とは思ったんですけど。この気持ちは一体……
![](/wp-content/include/images/avatar/teacher/7.png)
関数の名前に注目してみましょう。