//
// main.m
// C7_结构体
//
// Created by dllo on 15/7/8.
// Copyright (c) 2015年 Clare. All rights reserved.
//
#import <Foundation/Foundation.h>
//struct student{
// // 结构体的每一条内容称为成员变量
// int stuAge; // 学生的年龄
// float stuScore; // 学生成绩
// char stuSex; // 学生性别
// char stuName[20]; // 学生姓名
//};
// 定义一个书的类型,书名,价格,页数,作者,出版社
struct book{
char bookName[20];
float price;
int page;
char author[20];
char publisher[20];
};
typedef struct book Book;
// 定义一个car类型的结构体
// 车的品牌,轮胎数,颜色,价格
struct car{
char carBrand[20];
int carTyre;
char carColor[20];
float price;
};
//typedef struct student Student;
//
//typedef int DT;
// typedef的第二种写法
typedef struct student{
int stuAge;
float stuScore;
char stuSex;
char stuName[20];
}Student;
// 结构体位于主函数的上方import下方
int main(int argc, const char * argv[]) {
// int arr[7] = { 3, 58, 5, 87, 75, 22, 32};
// for (int i = 0; i < 7; i++) {//循环几次
// for (int j = 0; j < 7 - 1 - i; j++) { // 内循环可以找到最大的数
// if (arr[j] > arr[j + 1]) {
// int temp = 0;
// temp = arr[j];
// arr[j] = arr[j+1];
// arr[j+1]= temp;
// }
// }
// }
// for (int i = 0; i < 7; i++) {
// printf("%d ",arr[i]);
// }
// // 结构体
// int arr[3] = {1, 2, 3};
// char str[20] = "111"; // 最多只能看见19个字符,因为还有一个'\0'结束符
// // 一维数组元素类型必须相同
// 把结构体看成是一个自定义的数据类型,可以定义结构体类型所对应的变量
// 定义一个学生类型的变量
// struct student stu = {20, 90.5, 'w', "zhangsan"}; // 赋值顺序和成员变量顺序一致
// // 打印学生的年龄
// printf("%d\n", stu.stuAge);
// stu.stuAge = 100;
// printf("%d\n", stu.stuAge);
// struct book book = {"hello word", 58.3, 200, "Selina", "北京"};
// printf("%s\n",book.author);
// // 书的类型所对应的变量
// struct book book1 = {"hello word", 58.3, 200, "Selina", "北京"};
// printf("%s\n",book1.bookName);
// //如果想要改变字符串里的内容,不能使用直接=的方式,而要用strcpy
// strcpy(book1.bookName, "sangguo");
// printf("%s\n",book1.bookName);
// // 只要是操作字符串,要用字符串的方法,比如strcpy等
// struct car car = { "maserati", 4, 100000000, "blue"};
// int a = 10;
// DT b = 20;
// printf("%d\n", b);
//
// 用新的变量名来定义一个变量
Student stu = {20, 50.5, 'w', "lisi"};
printf("\n");
return 0;
}