我有一个模式打开的程序文件,但我不太明白,在这种模式下打开文件意味着什么 . 根据定义,此模式打开一个文件,用于读取和写入(在文件末尾) . 但是下面我的程序的输出只是打开它进行写入(没有显示打印文件,如阅读模式所暗示的那样) . 可以有人解释一下这个模式实际上做了什么以及它与其他打开模式的比较
#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <errno.h>
int main(void)
{
unsigned int account; // account number
char name[30]; // account name
double balance; // account balance
char ch;
FILE *cfPtr; // cfPtr = clients.dat file pointer
// fopen opens file; exits program if file cannot be opened
if ((cfPtr = fopen("clients.txt", "a+")) == NULL)
{
perror(cfPtr);
puts("File could not be opened");
} // end if
else
{
printf("%-10s%-13s%s\n", "Account", "Name", "Balance");
fscanf(cfPtr, "%d%29s%lf", &account, name, &balance);
// while not end of file 22
while ((ch = getc(cfPtr)) != EOF)
{
printf("%-10d%-13s%7.2f\n", account, name, balance);
fscanf(cfPtr, "%d%29s%lf", &account, name, &balance);
}
}
system("pause");
}