生徒1の名前が空白であるかどうかを確認するコードを作成し、 。ただし、このコードを使用すると、そのメッセージは表示されません。私がenterを押すと、実際に何かを入力するまでカーソルが次の行に移動します。これもstrcmpで試してみましたが、何も動作しません。Cで文字列が空であることを確認する方法(これまでに何もできていない)
#include <stdio.h>
#include <string.h>
{
char charStudent1FirstName[50] = "";
printf("Please enter Student 1's First name: ");
scanf("%s", &charStudent1FirstName);
if (charStudent1FirstName[0] == '\0')
{
printf("Please input Student 1's first name again: ");
scanf("%s", &charStudent1FirstName);
}
}
可能な重複(https://stackoverflow.com/questions/9609662/idiomatic-way-of- char-check-for-empty-string-in-c?rq = 1) – Barnabus
'&charStudent1FirstName'ではなく、' charStudent1FirstName'が必要であることに注意してください。あなたのコンパイラはあなたに警告していませんでしたか? – smarx
@BarnabusそれはOPの実際の問題ではありません。 – jamesdlin