我无法在c中打开文件

rip*_*ppy 1 c fopen file

我在d:drive中创建了一个名为abc的文本文件.我无法打开它.请告诉我怎么做.

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
    FILE *fp;
    clrscr();
    fp = fopen("D:/abc.txt","r");
    if(fp == NULL)
    {
        printf("\nCannot open");
        getch();
        exit(1);
    }
    fclose(fp);
    getch();
}
Run Code Online (Sandbox Code Playgroud)

小智 5

你有一个错字,试试吧

 fp = fopen("D:\\abc.txt","r");
Run Code Online (Sandbox Code Playgroud)

代替.

或者,如果文件与程序位于同一文件夹中:

 fp = fopen("abc.txt","r");
Run Code Online (Sandbox Code Playgroud)