练习1:
先创建一个文件c:\temp\loans.txt,文件包含的内容为:
11111
22222
33333
44444
55555
循环读取并显示该文件中的每行数据,脚本如下:
Actions()
{
int MyFile;
int LoanNumber,i;
// Assigning the file path to a string
char FileName[80] = "C:\\temp\\loans.txt";
// Opening the file
// Note the use of variable to replace the file path
//
MyFile = (int)fopen(FileName,"r");
// Reading and printing one loan number at a time
for(i=1;i<=5;i++)
{
fscanf(MyFile,"%d", &LoanNumber);
lr_output_message("Loan Number %d: %d",i,LoanNumber);
}
fclose(MyFile);
return 0;
}