ユーザーが入力した見積もりを読むためにswitchステートメントを作成しようとしています。私が抱えている問題は、最初の文字を読むだけで、プログラムが終了することです。リストされた条件に対して、すべての文字を入力して測定する必要があります。私はC言語に新しいので、配列段階ではまだありません。私はちょうど私が間違って行くポインタを必要とする!C言語スイッチステートメントがフル文字入力を読み取っていません
#include "stdafx.h"
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include <string.h>
int main()
{
int c;
int temp = 0;
int ch;
int reader;
printf("Enter 1-read from keyboard or 2-read from file\n");
scanf_s("%d", &reader);
switch (reader) {
case 1:
printf("Please enter a quote\n");//user input characters
scanf_s("%c", &c);
while ((c = _getch()) !='\n'){ //reads each character and checks for end of line
printf("\n%c", c);
if (temp == c)
printf(" duplicate character");
if ((c) == 'a' || (c) == 'e' || (c) == 'i' || (c) == 'o' || (c) == 'u')
printf(" vowel is lower case");
if ((c) == 'A' || (c) == 'E' || (c) == 'I' || (c) == 'O' || (c) == 'U')
printf(" vowel is upper case");
if (ispunct(c))//checks for punctuation
printf(" punctuation");
temp = c;
break;
case 2:
printf("I need some help");
break;
default:
break;
}
}
return 0;
}
ループ文はどこにありますか? – Olaf
あなたの 'while'と' cases'はクロスネストです。つまり 'case1'の半分で、' case2: 'と' default'は 'while'ループの中にあります。それは本当にあなたの意図ですか? – rodrigo
'scanf_s("%c "、&c);' - > 'scanf_s("%c "、&c, 1);')、長さ引数を追加し、[scanf_s'のマニュアルページ(https://msdn.microsoft。とにかく2つの入力スタイルを混合しているのはなぜですか? –