c
1#include <stdio.h>
2
3int pass = 1234;
4int entpass;
5
6int main(void)
7{
8 printf("入力された番号が正しいか確認します。\n");
9 scanf("%d", &entpass);
10 while (1) {
11 if (pass == entpass) {
12 printf("入力された番号は正しいです。\n");
13 break;
14 } else {
15 printf("入力された番号が間違っています。\n");
16 }
17 }
18 return 0;
19}
なぜ、passとentpassが外部に有るのでしょう?
text
1t3.c:3:5: warning: no previous extern declaration for non-static variable 'pass'
2 [-Wmissing-variable-declarations]
3int pass = 1234;
4 ^
5t3.c:4:5: warning: no previous extern declaration for non-static variable 'entpass'
6 [-Wmissing-variable-declarations]
7int entpass;
8 ^
92 warnings generated.
また、scanf("%d", &entpass);はループの中に無いとおかしいのでは?
c
1usr ~/Project/test % ./a.out
2入力された番号が正しいか確認します。
3123
4入力された番号が間違っています。
51234
6入力された番号は正しいです。
7usr ~/Project/test % cat t3.c
8#include <stdio.h>
9
10int main(void)
11{
12 int pass = 1234;
13 int entpass;
14 printf("入力された番号が正しいか確認します。\n");
15 while (1) {
16 scanf("%d", &entpass);
17 if (pass == entpass) {
18 printf("入力された番号は正しいです。\n");
19 break;
20 } else {
21 printf("入力された番号が間違っています。\n");
22 }
23 }
24 return 0;
25}
26usr ~/Project/test %
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。