basic file handling problem
Hello,
I've got an assignment where the first section involves asking the user for the name of the file to open, if the file does not exist, then a file should be created. I thought that i had acheived this but it still doesnt function the way i want to. If the file doesn't exist, it doesn't seem to go in the IF loop where it should print the 'file not found' message. Can someone give me some guidance please.
Code:
// Barcode1.cpp : Defines the entry point for the console application.
#include <stdio.h>
int main()
{
FILE *fin, *fout;
char barfile[100];
printf("Please enter the name of the file you wish to open..\n");
scanf("%s", &barfile);
fin = fopen(barfile, "a");
if (fin==NULL) {
printf("File has not been found. File will be created.\n");
fout=fopen(barfile,"a");
}
printf("Start scan now, press any key to stop scan..\n");
{
}
}
thanks
George