#include "stdafx.h"
#include "string.h"
#include "stdio.h"
void CharReadWrite(FILE *fin);
FILE *fptr2;
int _tmain(int argc, _TCHAR* argv[])
{
char filename[]="ReadMe.txt";
if (fopen_s( &fptr2, filename, "r" ) != 0 )
printf( "File stream %s was not opened\n", filename );
else
printf( "The file %s was opened\n", filename );
CharReadWrite(fptr2);
fclose(fptr2);
return 0;
}
void CharReadWrite(FILE *fin){
int c;
while ((c=fgetc(fin)) !=EOF) {
putchar(c);}
}
您正在打开 ReadMe.txt 进行写作:
fopen_s( &fptr2, filename, "w" )
然后将其传递给 CharReadWrite
:
CharReadWrite(fptr2);
它试图从中读取:
c=fgetc(fin)
您是要通过将 “r”
传递给 fopen_s
来打开它进行阅读吗?
如果打开 ReadMe.txt 失败,您还可以继续调用 CharReadWrite
。
我是一名优秀的程序员,十分优秀!