donotopen

Embed Size (px)

DESCRIPTION

C Program to open files

Citation preview

  • //fileopen.c //Created by Andy Richardson//Demonstrates opening a file and handling an invalid file name

    #include #include #include

    int main(){char str[35]; //Stores file name such as "file.txt"printf("Enter file name: ");gets(str);

    FILE *file; //Checks if file can be opened, if not returns error and closes.

    if ((file = fopen(str, "r")) == NULL){printf("Unable to open file. File not found! \n");exit(0);

    }else{printf("File Opened");

    }