Y
YiMkiE
I am trying to get the user to input the name of the .csv file they
want to check if it exist and also the name of the text file they want
to store the error if file is not exist. The following is the full
source. I found that every time it generate a .csv file for the error
log, instead of a txt file. What's wrong?
#include <stdio.h>
#include <time.h>
#include <string.h>
int main()
{
int e = 1;
FILE *fp;
char in[9]; //stores the file name for checking
char out[21]; //stores the file name for output in case file is
not found
char AMH[] = "S:\\wmp\\mgt info\\DCD\\SDWAMH\\AMH_TdySales-";
time_t rawtime;
struct tm * timeinfo;
char err[20];
rawtime = time (NULL);
timeinfo = localtime (&rawtime);
strftime(err, 21, "%x %X ", timeinfo);
scanf("%s", in);
scanf("%s", out);
strncat(out, ".txt", 5);
strncat(AMH, in, 8);
strncat(AMH, ".csv", 5);
/* check AMH Report */
if ((fp = fopen(AMH, "r")) == NULL){
fp = fopen(out, "a");
fprintf(fp, "%s %s File not found\n", err, AMH);
fclose(fp);
//printf("%s File not found!\n", AMH);
}
return 0;
}
want to check if it exist and also the name of the text file they want
to store the error if file is not exist. The following is the full
source. I found that every time it generate a .csv file for the error
log, instead of a txt file. What's wrong?
#include <stdio.h>
#include <time.h>
#include <string.h>
int main()
{
int e = 1;
FILE *fp;
char in[9]; //stores the file name for checking
char out[21]; //stores the file name for output in case file is
not found
char AMH[] = "S:\\wmp\\mgt info\\DCD\\SDWAMH\\AMH_TdySales-";
time_t rawtime;
struct tm * timeinfo;
char err[20];
rawtime = time (NULL);
timeinfo = localtime (&rawtime);
strftime(err, 21, "%x %X ", timeinfo);
scanf("%s", in);
scanf("%s", out);
strncat(out, ".txt", 5);
strncat(AMH, in, 8);
strncat(AMH, ".csv", 5);
/* check AMH Report */
if ((fp = fopen(AMH, "r")) == NULL){
fp = fopen(out, "a");
fprintf(fp, "%s %s File not found\n", err, AMH);
fclose(fp);
//printf("%s File not found!\n", AMH);
}
return 0;
}