C语言 结构体函数之传址调用
2022/1/14 6:06:41
本文主要是介绍C语言 结构体函数之传址调用,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
执行结果截图:
代码:
#include "stdio.h" #include "stdlib.h" # define PRINTF(templt, ...) fprintf(stderr, templt, ##__VA_ARGS__) # define PRINT(format, ...) printf(# format, ##__VA_ARGS__) struct Date { int year; int month; int day; }; struct Book { char title[120]; char author[40]; float price; struct Date date; char publisher[40]; }; void getBookInput(struct Book * book); void printBook(struct Book * book); void getBookInput(struct Book * book) { // 输入结构体变量的值并打印 PRINT(请输入书名 :); scanf("%s", book->title); PRINT(请输入作者 :); scanf("%s", book->author); PRINT(请输入售价 :); scanf("%f", &book->price); PRINT(请输入出版日期(按年月日依次输入):); scanf("%d", &book->date.year); scanf("%d", &book->date.month); scanf("%d", &book->date.day); PRINT(请输入出版社 :); scanf("%s", book->publisher); } void printBook(struct Book * book) { PRINT(书名 : %s\n, book->title); PRINT(作者 : %s\n, book->author); PRINT(售价 : %.2f\n, book->price); PRINT(出版日期 : %d-%d-%d\n, book->date.year, book->date.month, book->date.day); PRINT(出版社 : %s\n, book->publisher); } int main() { struct Book b1; struct Book b2; PRINT(\n请录入第一本书的信息...\n); getBookInput(&b1); putchar('\n'); PRINT(请录入第二本书的信息...\n); getBookInput(&b2); PRINT(\n\n录入完毕,现在开始打印验证...\n\n); PRINT(打印第一本书的信息...\n); printBook(&b1); putchar('\n'); PRINT(打印第二本书的信息...\n); printBook(&b2); return 0; }
这篇关于C语言 结构体函数之传址调用的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-09-28pyqt 怎么打包整个项目-icode9专业技术文章分享
- 2024-09-28laravel Commands 创建带有参数的 Artisan 命令的步骤和示例-icode9专业技术文章分享
- 2024-09-28antd怎么实现渲染tiff图片-icode9专业技术文章分享
- 2024-09-28英文半角中划线和中文全角的中划线有什么区别-icode9专业技术文章分享
- 2024-09-28nvm npm 和node 他们之间有什么关系-icode9专业技术文章分享
- 2024-09-28Node Version Manager (nvm)使用教程-icode9专业技术文章分享
- 2024-09-28nvm命令太慢,是什么原因-icode9专业技术文章分享
- 2024-09-28Kotlin 如何增加、删除和修改 MutableStateFlow 中的值。-icode9专业技术文章分享
- 2024-09-28Kotlin的stateFlow.update 写法介绍-icode9专业技术文章分享
- 2024-09-28kotlin 怎么获取当前时间格式-icode9专业技术文章分享