#include <stdio.h>
int main(){
char testChar;
printf("%d\n", scanf("%c", &testChar));
return 0;
}
내가 원했던 것은 스캔 한 문자 수를 인쇄하는 것이 었습니다. 그러나 입력 한 내용이 모두 동일한 출력 즉, 1 일 때이 코드가 모든 입력에 대해 "1"로 인쇄되는 이유는 무엇입니까?
#include <stdio.h>
int main(){
char testChar;
printf("%d\n", scanf("%c", &testChar));
return 0;
}
내가 원했던 것은 스캔 한 문자 수를 인쇄하는 것이 었습니다. 그러나 입력 한 내용이 모두 동일한 출력 즉, 1 일 때이 코드가 모든 입력에 대해 "1"로 인쇄되는 이유는 무엇입니까?
scanf()
only scans your first character input and returns 1.
당신은 stdin
에서 읽은 문자의 수를 출력하려면이 옵션을 시도 할 수 있습니다. 루프에서 scanf
을 사용합니다.
#include <stdio.h>
#include <stdlib.h>
int
main(void) {
char testChar;
int numchar = 0;
printf("Enter characters, CTRL-C to end:\n");
while (scanf("%c", &testChar) == 1) {
numchar++;
}
printf("Number of characters scanned: %d\n", numchar);
return 0;
}
예, 1 문자를 스캔했기 때문입니다. – melpomene
아마도'scanf' 문서를 읽고 싶을 것입니다. 물어보기 전에 최소한 ** 약간의 연구를해야합니다! – Olaf