-
카테고리
-
세부 분야
프로그래밍 언어
-
해결 여부
미해결
교수님 s_gets 함수를 만드는 이유는 무엇인가요?
20.02.23 21:03 작성 조회수 342
0
#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