//loadrunner中应用结构的脚本学习
struct student
{
int num; //学号
char name[8]; //姓名
int age; //年龄
char sex[2]; //性别
float chinesescore; //语文成绩
float mathscore; //数学成绩
};
Action02()
{
//为结构数组赋前2个结构数组元素值
struct student stu[3] =
{
{101, "孙悟空", 30, "男", 100.00, 100.00},
{102, "沙和尚", 28, "男", 99.00, 99.00}
};
struct student stu1={103, "白骨精", 99, "女"}; //为结构变量stu1赋部分数据
int i;
stu1.chinesescore = 90.50;
stu1.mathscore = 89.00;
stu[2] = stu1; //将stu1变量赋给数组元素stu[2]
for (i =0; i <=2; i++)
{
lr_output_message("------------------------------");
lr_output_message("第 %d 个学生信息:", i+1);
lr_output_message("学号= %d", stu[i].num);
lr_output_message("姓名= %s", stu[i].name);
lr_output_message("年龄= %d", stu[i].age);
lr_output_message("性别= %s", stu[i].sex);
lr_output_message("语文成绩= %.2f", stu[i].chinesescore);
lr_output_message("数学成绩= %.2f", stu[i].mathscore);
}
return 0;
}
为了引用结构方便,可以应用类型定义符“”“typedef”将 struct student 命名成简单明了的名称。C语言允许由用户自己定义类型说明符,允许用户为数据类型取别名。脚本如下:
//loadrunner中应用结构的脚本学习
typedef struct student
{
int num; //学号
char name[8]; //姓名
int age; //年龄
char sex[2]; //性别
float chinesescore; //语文成绩
float mathscore; //数学成绩
}STU;
Action02()
{
//为结构数组赋前2个结构数组元素值
STU stu[3] =
{
{101, "孙悟空", 30, "男", 100.00, 100.00},
{102, "沙和尚", 28, "男", 99.00, 99.00}
};
STU stu1={103, "白骨精", 99, "女"}; //为结构变量stu1赋部分数据
int i;
stu1.chinesescore = 90.50;
stu1.mathscore = 89.00;
stu[2] = stu1; //将stu1变量赋给数组元素stu[2]
for (i =0; i <=2; i++)
{
lr_output_message("------------------------------");
lr_output_message("第 %d 个学生信息:", i+1);
lr_output_message("学号= %d", stu[i].num);
lr_output_message("姓名= %s", stu[i].name);
lr_output_message("年龄= %d", stu[i].age);
lr_output_message("性别= %s", stu[i].sex);
lr_output_message("语文成绩= %.2f", stu[i].chinesescore);
lr_output_message("数学成绩= %.2f", stu[i].mathscore);
}
return 0;
}
来源:oschina
链接:https://my.oschina.net/u/4842207/blog/4822596