You are on page 1of 1

//fileopen.

c
//Created by Andy Richardson
//Demonstrates opening a file and handling an invalid file name
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
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 clo
ses.
if ((file = fopen(str, "r")) == NULL){
printf("Unable to open file. File not found! \n");
exit(0);
}else{
printf("File Opened");
}

You might also like