- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- struct books{
- char name[20];
- char author[20];
- float price[20];
- };
- int i = 1;
- int main(void)
- {
- struct books library;
- printf("name of the book?\n");
- scanf_s("%s", library.name,20);
- printf("author of the book?\n");
- scanf_s("%s", library.author,20);
- printf("price of the book?\n");
- scanf("%f", &library.price[i-1]);
- int answer = 0;
- if (scanf("%d", &answer) == 1)
- {
- printf("You got %d books\n", i);
- for (; i > 0; i--)
- {
- printf("book number:%d\n", i);
- printf("name:%s\n", library.name);
- printf("author:%s\n", library.author);
- printf("price:%f\n", library.price[i-1]);
- }
- return 0;
- }
- else i++;
- return 1;
- }
- 字符数组不用&,字符数组的名字就代表的是首地址
复制代码 |