|
#include "stdafx.h"
#include "stdio.h"
#include "string.h"
void main() //计算器4则运算自动化测试脚本
{
int caseid,num1,num2,ex_result,result;
int i=0;
char oper;
FILE *p,*p1;
p=fopen("C:\\a.txt","r"); // 文件指针变量=fopen("文件名","文件使用方式"),C盘根目录存放a.txt文件
if(p==NULL) // 必须判断文件是否为空
{
printf("the input file is not found\n");
}
p1=fopen("C:\\b.txt","w");//b.txt存放测试运行结果
if(p1==NULL) // 必须判断文件是否为空
{
printf("the output file is not found\n");
}
while(i<4) //当a.txt中case数量很多?i不明确?如何自动判断文件读取结束??请帮忙写出修改
{
fscanf(p,"%d\t%d\t%c\t%d%d",&caseid,&num1,&oper,&num2,&ex_result);
switch(oper)
{
case '+' : result=num1+num2;break;
case '-' : result=num1-num2;break;
case '*' : result=num1*num2;break;
default: result=num1/num2;
}
if(result==ex_result)
{
fprintf(p1,"%d\t%s\n",caseid,"Passed");
}
else
{
fprintf(p1,"%d\t%S\n",caseid,"fail");
}
i++;
}
fclose(p1);
fclose(p);
} |
|