File Creation with fixed PREFIX & SUFFIX !!!
Dear Friends,
stuck again .... first let me give the code having no syntactical error but does not suffice the desire result.
-----------
char *HotName="HOT\0";
char *Extension="LOG\0";
printf("\n\n the OLD Name of file is %s \n\n ",HotName);
printf("\n\n the OLD Extension name is %s \n\n ",Extension);
if(CreateFile() != SUCCESS)
{
printf("\ncftodat. Process %d Error Creating the ERROR file ..\r\n",pid);
printf("\ncftodat. Process %d Terminating ..\r\n",pid);
exit(0);
}
printf("\n\n the file name is %s \n\n ",HotName);
printf("\n\n the Extension name is %s \n\n ",Extension);
strcat(HotName,Extension);
printf("\n\n the NEW Extension name is %s\n\n ",Extension);
printf("\n\n the file name after Extension concatination is %s \n\n ",HotName);
-----
int CreateFile()
{
char TmpDt[50], *tmpname, tmpname1[50] ;
tmpname = tmpnam(NULL);
sprintf(TmpDt,"%s %s",DATE,tmpname);
system(TmpDt);
ftemp = fopen(tmpname,"r");
if (ftemp == NULL)
{
printf("Error in the file ....\n\n");
exit(0);
}
fscanf(ftemp,"%s",tmpname1);
fclose(ftemp);
unlink(tmpname);
strcat(HotName,tmpname1);
return(SUCCESS);
}
-------
after running the program am getting the result as ...... OUTPUT...
the OLD Name of file is HOT
the OLD Extension name is LOG
the file name is HOT020729155246
the Extension name is 9155246 ---- wrong here .... should be only --- > LOG
the NEW Extension name is 915524691552469UNIX ---- wrong here .... should be HOT020729155246LOG
the file name after Extension concatination is HOT02072915524691552469UNIX ---- wrong here .... should be should be HOT020729155246LOG
the expected result is mentioned above ..... adjacent to the output..
Please help ..... find out where the error is ....
I am struggling with this since last 2 hours.
with best regards
Mehul Doshi
Re: File Creation with fixed PREFIX & SUFFIX !!!
Quote:
Originally posted by mehuldoshi
char *HotName="HOT\0";
char *Extension="LOG\0";
strcat(HotName,tmpname1);
You don't have to add the \0 character to the strings. This is automatically done.
The HotName and Extension variables are both constant character array's, fixed length and can't be changed. If you want to add (strcat) something to the strings, use something like this:
Code:
char HotName[1024];
strcpy(HotName, "HOT");
strcat(HotName, tmpname1);
File Creation with fixed Prefix & Suffix - DONE !!
Dear Friend,
The problem is solved and I am proceeding to the further part of my project ....
Thank you for the support. Would look forward for similar support in future ...
with best regards
Mehul Doshi