hello, ive worked on it somemore, but im still finding trouble doing the file handling, i still dont have a full grasp on it. i think my logic is right how: if it doesnt find the file, its goes to the if(NULL) statement, then creates a file. However, the problem i have now is that it does not concatenate '.txt' at the end of the newly created file. i got the strcat working if i added it after the very first fin command, but now when it creates the file, it doesnt add the .txt extension on the end. could i get some more guidance please.
thanks in advance
george
Code:
// Barcode1.cpp : Defines the entry point for the console application.
#include <stdio.h>
#include <conio.h>
#include <string.h>
int main()
{
FILE *fin;
char barfile[100];
char ext[5] = {'.','t','x','t'};
printf("Please enter the name of the file you wish to open..\n");
scanf("%c", &barfile);
fin = fopen(barfile, "w");
// strcat(barfile,ext);
//printf(" %c", barfile);
if (fin==NULL) {
printf("File has not been found. File will be created.\n");
fin=fopen(barfile,"a");
strcat(barfile,ext);
}
// fin=fopen(barfile,"w");
//strcat(barfile,ext);
printf("Start scan now, press any key to stop scan..\n");
while(1)
{
if(kbhit())
{
printf("Scanning stopping...\n");
break;
}
}
printf("To start another scan, press 1..\n");
}