How to open a file in c









#include<stdio.h>
int main(){
    FILE *ptr; //It is file pointer
   
    //opening the file in read mode in Linux os
    ptr = fopen("/root/Test/abc.c","r");

    //Opening the file in read mode in window os
    // ptr = fopen("C:\\Test\\abc.c","r");
   
    //Checking the status and printing message
    if(ptr == NULL)
         printf("Error in opening the file");
    else
         printf("File has opened successfully in read mode");

    return 0;
}









No comments: