im new to program and have written a bit of code for my class but i want it to display a error message rather than crash if the user enters a invalid file name? i think i should use a if statment but i cant get the sintax right.
Code:
#include <stdlib.h>
#include <stdio.h>
//a program that reads in a text file chosen by the user character by character and prints it out on the screen by Thomas collyer 01.12.10
void main ()//defines a program called main
{
FILE *file_in;//defines the stream as file in
char letter, destination[30]; //defines a string for each character and and array for the name of the text file
printf("please enter the file destination you want to read in\n");//gets the user to enter a file
scanf("%s" , destination);//reads in the destination and stores it in destination variable
file_in=fopen(destination, "r");// opens and reads the file
do//reads in the file and prints the file untill the end of file condition is met.
{
letter=getc(file_in);//reads each letter in one at a time to the letter variable
printf("%c" , letter);//prints each letter out on the screen
}
while
(letter != EOF);//checks if has reached the end of the text file
fclose(file_in);//closes the stream
}