loadrunner写入数据到文件

 

首先在F盘创建:

F:\\LR\\test.txt文件

#define USERCOUNT 100   							//定义参数数量
Action()
{

    char *namecommon="testA";						//用户名通用部分,根据需要修改
    char *passwordcommon="testB";					//密码通用部分,根据需要修改
    char *filename = "F:\\LR\\test.txt";			//参数文件保存路径,根据需要修改
    
    char username[20];								//保存用户名的字符数组
    char password[20];								//保存密码的字符数组
    int i=0;
    long file;										//指向文件的指针

     //用于打开文件
     if ((file = fopen(filename, "w+" )) == NULL) {

          lr_output_message("Unable to create %s", filename);
          return -1;

     }

     //创建用户名与密码,然后写入到文件中
    for(i=0;i< USERCOUNT;i++)
	{
	   sprintf(username,"%s%d",namecommon,i);		//创建用户名信息
       sprintf(password,"%s%d",passwordcommon,i); 	//创建密码信息

	   strcat(username," ");						//用空格分隔用户名与密码
       strcat(username,password);					//连接用户名与密码
	   strcat(username,"\r\n");						//添加回车换行标识

       fwrite(username,strlen(username),1,file);	//把一组用户信息写入参数文件
  
  }

    fclose(file);//关闭文件

 return 0;

}

效果如图:

执行脚本:

posted @ 2015-11-16 15:10  Agoly  阅读(2082)  评论(0编辑  收藏  举报