标题: 为什么写不入文件? [打印本页] 作者: breezeforever 时间: 2009-11-11 15:22 标题: 为什么写不入文件? int MyFile;
int LoanNumber,i;
// Assigning the file path to a string
char FileName[80] = "E:\\TestProj\\Award\\test.txt";
// Opening the file
// Note the use of variable to replace the file path
//
MyFile = (int)fopen(FileName,"w");
// 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;作者: qiguojie 时间: 2009-11-12 11:36
Long MyFile;
int LoanNumber,i; //不知道LoanNumber是从什么地方获取的,也许有其他的脚本,到打印的时候也没有赋值
char *FileName = "E:\\TestProj\\Award\\test.txt";
MyFile = fopen(FileName,"a+");
for(i=1;i<=5;i++)
{
fprintf(MyFile,"%d", &LoanNumber);
lr_output_message("Loan Number %d: %d",i,LoanNumber);
}
fclose(MyFile);
//这样应该就没问题了吧作者: gnixougil 时间: 2009-11-12 13:35
你用错函数了
Long MyFile;
int LoanNumber,i; //不知道LoanNumber是从什么地方获取的,也许有其他的脚本,到打印的时候也没有赋值
char *FileName = "E:\\TestProj\\Award\\test.txt";
MyFile = fopen(FileName,"a+");\\The type fo access mode: r, w, a or r+, w+, a+, where the "+" sign
// indicates that the file must already exist.
for(i=1;i<=5;i++)
{
fprintf(MyFile,"%d", LoanNumber);
lr_output_message("Loan Number %d: %d",i,LoanNumber);
}
fclose(MyFile);