C언어 온라인 오류 해결 부탁드립니다.

조회수 774회
#include <stdio.h>
#include <string.h>

void main()
{
    struct Person {
        char name[50]; // 이름
        int age;
        char sex;
        char* namep; // 성을 가리키는 포인터
    } student;

    while (1) {
        printf("Provide your personal information:\n");
        printf("Name : ");
        //name의 입력값이 stop일 경우 종료하기
        scanf("%[^\n]", student.name);
        if (strcmp(student.name, "stop") == 0) break;
        rewind(stdin);
        //나이 입력
        printf("Age : ");
        scanf("%d", &student.age);
        rewind(stdin);
        //성별 입력
        printf("Sex(M/F) :");
        scanf("%c", &student.sex);
        rewind(stdin);

        student.namep = strtok(student.name, " ");
        student.namep = strtok(NULL, " ");


        printf("Your name is %s %s, your age is %d, your sex is %c\n\n", student.namep, student.name, student.age, student.sex);

    }
}

어떤 사람 이름 성 나이 성별 순으로 입력 받아서 성 이름 나이 성별로 출력하는 간단한 프로젝트인데 https://www.onlinegdb.com/online_c_compiler 에서 컴파일 했을 때

  1. 왜 rewind를 했음에도 불구하고 성별 입력이 무시 되는지 이해가 안 갑니다.
  2. 성별 입력 부분에 %c로 입력한 경우 첫번 째에는 제대로 작동하는데 다음 입력부터 name: age: 이런식으로 오류가 발생하는데 그 이유는 뭔가요?

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)