@SuHongjun
2020-04-30T03:24:33.000000Z
字数 2886
阅读 969
C语言
#include "stdio.h"
struct BOOK //结构体类型定义,BOOK是类型名,定义的新类型是:struct BOOK类型
{
char ISBN[50]; //结构体的成员
char bookname[100];
char author[100];
float price;
int soldCount;
};
main()
{
struct BOOK b[100]; //b是一个结构体数组,数组元素的类型是:struct BOOK
}
#include "stdio.h"
//自定义类型
struct Book // 类型定义
{
char ISBN[50]; //成员
char bookName[100];
char author[100];
float price;
int soldCount; //小驼峰命名法
};
//函数原型声明
main()
{
struct Book book1,book2; //变量定义,struct Book是类型,book1、book2是变量
}
//函数定义
#include "stdio.h"
//自定义类型
//函数原型声明
main()
{
}
//函数定义
#include "stdio.h"
struct BOOK //结构体类型定义,BOOK是类型名,定义的新类型是:struct BOOK类型
{
char ISBN[50]; //结构体的成员
char bookName[100];
char author[100];
float price;
int soldCount;
};
main()
{
struct BOOK book1; //book1是struct BOOK 类型的一个变量;
struct BOOK book2 = {"9787001","西游记","吴承恩",34.8,46}; //结构体变量初始化
struct BOOK ba1[100]; //ba1是结构体数组
struct BOOK ba2[100] = {
{"9787001","西游记","吴承恩",34.8,46},
{"9787002","狼图腾","姜蓉",45.8,67},
{"9787003","红与黑","司汤达",25.8,21},
}; //结构体数组的初始化,部分初始化
}
#include "stdio.h"
struct BOOK //结构体类型定义,BOOK是类型名,定义的新类型是:struct BOOK类型
{
char ISBN[50]; //结构体的成员
char bookName[100];
char author[100];
float price;
int soldCount;
};
main()
{
int i;
struct BOOK book1; //book1是struct BOOK 类型的一个变量;
struct BOOK book2 = {"9787001","西游记","吴承恩",34.8,46}; //结构体变量初始化
struct BOOK ba1[100]; //ba1是结构体数组
struct BOOK ba2[100] = {
{"9787001","西游记","吴承恩",34.8,46},
{"9787002","狼图腾","姜蓉",45.8,67},
{"9787003","红与黑","司汤达",25.8,21},
}; //结构体数组的初始化,部分初始化
printf("图书信息:\n");
printf("===============================================================\n");
printf(" ISBN\t\t书名\t作者\t售价\t售出数量\n");
printf("---------------------------------------------------------------\n");
for(i=0; i<3; i++)
printf(" %s\t%s\t%s\t%.2f\t%5d\n",
ba2[i].ISBN, //结构体对成员的引用方式 .
ba2[i].bookName,
ba2[i].author,
ba2[i].price,
ba2[i].soldCount);
printf("===============================================================\n");
}
#include "stdio.h"
struct BOOK //结构体类型定义,BOOK是类型名,定义的新类型是:struct BOOK类型
{
char ISBN[50]; //结构体的成员
char bookName[100];
char author[100];
float price;
int soldCount;
};
main()
{
struct BOOK b[100]; //b是一个结构体数组,数组元素的类型是:struct BOOK
int i;
char buff[100];
printf("请录入图书信息:\n");
for(i=0; i<3; i++)
{
printf("第%d本书--ISBN:",i+1);
gets(b[i].ISBN); //b[i].ISBN 是数组名
printf("第%d本书--书名:",i+1);
gets(b[i].bookName); //b[i].bookName 是数组名
printf("第%d本书--作者:",i+1);
gets(b[i].author); //b[i].author 是数组名
printf("第%d本书--售价:",i+1);
scanf("%f",&b[i].price); //b[i].price 是float型
printf("第%d本书--售出数量:",i+1);
scanf("%d",&b[i].soldCount); //b[i].soldCount 是int型
gets(buff);
}
printf("已录入的图书信息:\n");
printf("===============================================================\n");
printf(" ISBN\t\t书名\t作者\t售价\t售出数量\n");
printf("---------------------------------------------------------------\n");
for(i=0; i<3; i++)
printf(" %s\t%s\t%s\t%.2f\t%5d\n",
b[i].ISBN,
b[i].bookName,
b[i].author,
b[i].price,
b[i].soldCount);
printf("===============================================================\n");
}
思考题:如何避免每次都要录入大量的数据?? (避免重复录入)
提示:文件操作