scanf 질문이 있습니다.

ljs0652의 이미지

char Time[24];
char A[20];
char B[20];

printf("입력 : ");
scanf("%s[^\n]", Time);
printf("입력 : ");
scanf("%s", A);
printf("입력 : ");
scanf("%s",B);

printf("Time : %s \n", Time);
printf("Time : %s \n", A);
printf("Time : %s \n", B);

이런식으로 입력을 받으면
Time에서 2018-01-01 까지만 받으면 셋다 정상적으로 받을 수 있는데
2018-01-10 20:20:20 이런식으로 받으면
두번째 A가 생략이 되고 세번째 B를 받게 됩니다 왜 이런 증상이 일어나는거죠??

세벌의 이미지

https://linux.die.net/man/3/scanf
를 보면 아래 내용이 있는데, 그것과 관련 있을것 같아요.

If the number of pointer arguments exceeds the number of conversion specifications, then the excess pointer arguments are evaluated, but are otherwise ignored.

raymundo의 이미지

%[^\n] 이라고 쓰셔야 할 곳을 %s[^\n]라고 쓰셔서 그렇습니다.

좋은 하루 되세요!