loadrunner写入数据到文件

 1 Action()
 2 {
 3     char *namecommon="testA";                      //用户名通用部分,根据需要修改
 4     char *passwordcommon="testB";                  //密码通用部分,根据需要修改
 5     char *filename = "D:\\test.txt";         //参数文件保存路径,根据需要修改
 6      
 7     char username[20];                             //保存用户名的字符数组
 8     char password[20];                             //保存密码的字符数组
 9     int i=0;
10     int USERCOUNT=10;
11     long file;                                     //指向文件的指针
12  
13      //用于打开文件
14      if ((file = fopen(filename, "w+" )) == NULL) {
15  
16           lr_output_message("Unable to create %s", filename);
17           return -1;
18  
19      }
20  
21      //创建用户名与密码,然后写入到文件中
22     for(i=0;i< USERCOUNT;i++)
23     {
24        sprintf(username,"%s%d",namecommon,i);        //创建用户名信息
25        sprintf(password,"%s%d",passwordcommon,i);   //创建密码信息
26  
27        strcat(username," ");                        //用空格分隔用户名与密码
28        strcat(username,password);                    //连接用户名与密码
29        strcat(username,"\r\n");                      //添加回车换行标识
30  
31        fwrite(username,strlen(username),1,file); //把一组用户信息写入参数文件
32    
33   }
34  
35     fclose(file);//关闭文件
36     return 0;
37 }

转载自:http://www.cnblogs.com/qmfsun/p/4968398.html

posted @ 2017-05-03 21:14  花醉红尘  阅读(572)  评论(0编辑  收藏  举报