探索测试之路。。。

lr里面file函数应用试题+答案

上一篇 / 下一篇  2007-09-05 11:19:03 / 个人分类:Loadrunner

Exercise :

Copy the following names into a text file and save it as c:\temp\data.txt

BlackDog

RockandRoll

TheBattleofEvermore

StairwaytoHeaven

MistyMountainHop

Write a program to read these names and print them into a new file c:\temp\data2.txt, each name twice. data2.txt should look like this:

BlackDog

BlackDog

RockandRoll

RockandRoll

TheBattleofEvermore

TheBattleofEvermore

StairwaytoHeaven

StairwaytoHeaven

MistyMountainHop

MistyMountainHop

 

答案:

Action17()
{
 int MyFile,MyFile1;
 char test1[500],test2[500];
 char File[15]="c:\\data.txt";
 MyFile = fopen(File,"r");
    MyFile1 = fopen("c:\\data1.txt","w");
 while(feof(MyFile)==0)
 {
  fscanf(MyFile,"%s",test1);
  strcat(test2,test1);
  strcat(test2,"\n");
  strcat(test2,test1);
  strcat(test2,"\n");
 }
    fprintf(MyFile1,"%s",test2);
 fclose(MyFile);
 fclose(MyFile1);
 return 0;
}

呵呵,感觉不是最优化的方法;


TAG: Loadrunner

 

评分:0

我来说两句

Open Toolbar