교수님 s_gets 함수를 만드는 이유는 무엇인가요?
547
작성한 질문수 6
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#define MAX_TITLE 40
#define MAX_AUTHOR 40
#define MAX_BOOKS 3
int main()
{
struct book
{
char title[MAX_TITLE];
char author[MAX_AUTHOR];
float price;
};
struct book library[MAX_BOOKS];
int count = 0;
while (1)
{
printf("input a book title or press [Enter] to stop.\n>>");
gets(library[count].title);
if (library[count].title[0] == '\0') break;
printf("input the author.\n>>");
gets(library[count].author);
printf("iuput the price.\n>>");
scanf("%f", &library[count].price);
while (getchar() != '\n') continue;
count++;
if (count == MAX_BOOKS) break;
}
if (count > 0)
{
printf("The list of books:\n");
for (int i = 0; i < count; i++)
printf("\"%s\" written by %s : %.1f\n", library[i].title, library[i].author, library[i].price);
}
else printf("There is noo book.");
return 0;
}
답변 2
0
안녕하세요?
아래 블로그의 내용이 도움이 될 수도 있을 것 같아요.
출처:
감사합니다.
0
위처럼 gets 함수를 써도 될거같은데.. 사실 전부분 강의에서 getchar 함수를 사용하는 부분을 좀 이해 못한 부분이 있긴 합니다.. 함수 나오는 강의 분:초는 4:26초 입니다.
완전히 똑같이 따라해도 exe파일이 안만들어져서 실행이 안됩니다.
1
51
3
main 함수에서 왜 int만 선언이 되는걸까요
1
56
2
8비트 2진수 변환시 왜 1을 더해야하나요?
1
54
2
혹시 강의를 빠르게 수강하려면 어디서부터 듣는게 좋을까요?
1
49
1
프로토타입과 함수간의 인자 불일치
1
73
2
12.12 헤더 관련 질문
1
60
2
Visual Studio Community 2026 사용 문의
1
137
2
Q. 15:30, 부호가 있는 8비트 정수 질문
1
60
2
getchar(), putchar()
1
93
3
강의자리ㅛ
1
79
2
비주얼스튜디오코드로 공부해도 상관없나요?
1
112
2
소스파일안에 여러 파일
1
75
2
F5와 F7의 차이
1
76
2
c = TWO * (a+b); 에서 a와 b는?
1
58
2
; 세미콜론을 붙이는 기준에 문의
1
68
1
Step over 기능 문의
1
53
2
2.6 강의 따옴표 출력 규칙 문의
1
74
2
int main 함수 관련 오류 문의
1
67
2
13.4 words[0]
0
60
2
11.7 함수를 구현해 봤습니다.
1
62
2
11.6 직접 strcmp와 strncmp를 구현해 보았습니다.
1
64
2
11.6 my_strcat과 my_strncat을 구현해봤습니다.
1
53
2
11.6 fit_str함수를 구현해 봤습니다.
1
53
2
11.5 코드 구현
1
67
2





