File Creation with fixed PREFIX & SUFFIX !!!

This is a discussion on File Creation with fixed PREFIX & SUFFIX !!! within the C Programming forums, part of the General Programming Boards category; Dear Friends, stuck again .... first let me give the code having no syntactical error but does not suffice the ...

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    19

    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

  2. #2
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680

    Re: File Creation with fixed PREFIX & SUFFIX !!!

    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);

  3. #3
    Registered User
    Join Date
    Jun 2002
    Posts
    19

    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File Writing Problem
    By polskash in forum C Programming
    Replies: 3
    Last Post: 02-13-2009, 10:47 AM
  2. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 04:44 PM
  3. Linking error
    By DockyD in forum C++ Programming
    Replies: 10
    Last Post: 01-20-2003, 05:27 AM
  4. Simple File Creation Algorithm
    By muffin in forum C Programming
    Replies: 13
    Last Post: 08-24-2001, 04:28 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21