2013-06-01 58 views
0

当我调试代码时,我在下面的程序中使用Turbo C.我总是在输出窗口中获得“无法读取文件”。文件的输入路径以“PR1.txt”形式给出,并且C:上也存在相同的文件。无法使用Turbo C在c中使用fopen函数打开文件

#include "stdio.h" 
    #include "stdlib.h" 

    void main(void) 
    { 
    FILE *fp; 
    int value; 
    char ch; 
    fp = fopen("PR1.txt","w"); 
    if(!fp) 
    { 
     printf("Cannot read file"); 
    } 
    else 
    { 
     printf ("\n entr char to wrtite in file ::"); 
     scanf("%c",&value); 
     fputc(ch,fp); 
     fclose(fp); 
     fp=fopen("PR1.c","r") ; 
     value=getc(fp); 
     printf("\n The result is= %d",value); 
     fclose(fp); 
     getch(); 
    } 

回答

0

你最好尝试

if(fp==NULL) 
    printf("Cannot Read File");