#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;ios
int main()
{
FILE *fp;
char ch;
if((fp=fopen("123.txt","r"))==NULL)
printf("file cannot open \n");
else
printf("file opened for writing \n");
while ( ( ch = fgetc(fp) ) != EOF ) // 注意,這裏使用char ch,實際上是不科學的,由於最後判斷結束標誌時,是看ch!=EOF,而EOF的值爲-1,這顯然和char是不能比較的。因此,某些使用,咱們都定義成int ch。
fputc(ch,stdout); //這裏是輸出到屏幕
if(fclose(fp)!=0)
printf("file cannot be closed \n");
else
printf("file is now closed \n");
return 0;
}spa