私はプログラミングの新機能です。自分のプログラムで2回目のキーボード入力を変更していないときに、これがなぜ機能しないのか分かりません。なぜこれは機能しません:scanf("%c",&ch3);
私は何が欠けていますか? は、ここに私のうちに置かれる:私のプログラムでscanfが2度目に動作しないのはなぜですか?
は、最初の文字を入力してください
文字が大文字です。
が第二の文字を入力してください:
これは無効な文字
をここでは、単一の文字を読み取ることがscanf
を使用している場合これは非常に共通の問題である私のコード
#include <stdio.h>
#include <stdlib.h>
int ifelse(char ch);
int main()
{
char ch2=NULL;
char ch3=NULL;
printf("please enter first the character : \n");
scanf("%c",&ch2);
if(ifelse(ch2)==1) //if(ifelse(ch2)==1) like this also can be use
{printf("The character is capital letter.\n");}
else if (ifelse(ch2)==2){printf("This is small letter character.\n");}
else if(ifelse(ch2)==3){printf("oh no! numeric letter.\n");}
else printf("this is invalid character\n");
printf("please enter second the character : \n");
scanf("%c",&ch3);
if(ifelse(ch3)==1) //if(ifelse(ch2)==1) like this also can be use
{printf("The character is capital letter.\n");}
else if (ifelse(ch3)==2){printf("This is small letter character.\n");}
else if(ifelse(ch3)==3){printf("oh no! numeric letter.\n");}
else printf("this is invalid character\n");
return 0;
}
int ifelse(char ch){
if (ch>='A'&&'Z'>=ch){ return 1;}
else if(ch>='a'&&'z'>=ch){ return 2;}
else if(ch>='0'&&'9'>=ch){ return 3;}
return 0;
}
「ch3」を印刷してみましたか? – John3136
@ John3136のようなデバッグアクションが必要です。このようなスキルはCのタグで禁止されているようです:( –