#include <stdio.h>
struct s_type {
int i;
char ch;
double d;
char str[79];
}s;
int main(void)
{
printf("enter an integer:");
scanf("%d", &s.i);
printf("enter a character:");
scanf("%c",&s.ch);
printf("enter a floating point number:");
scanf("%lf", &s.d);
printf("enter a string:");
scanf("%s",s.str);
printf("%d %c %lf %s", s.i,s.ch,s.d,s.str);
return 0;
}
혹시 visual c++ 있으신분 이거 실행해 보세요 왜 printf("enter a character:"); scanf("%c",&s.ch);
이부분은 실행안되고 그냥 넘어 가는걸까요 ㅜ.ㅜ 알려주세요~
그래서 첫 integer 입력때 "숫자 치고 엔터"를 쳤던거에서 엔터의 값이 버퍼에 저장되어있다가 char 입력을 받을 때 덥석 들어갑니다.
처리하는 방법은 char 입력을 받는걸 한번 더 해주면 되고, 아니면 버퍼 싸그리 지워주는 함수가 어디에 있었는데 그게 어느 헤더에 있었는지를 까먹었습니다. 한번 찾아보세요.