strcat and three strings

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • alternativa

    #1

    strcat and three strings

    Hi,
    I have a following problem: I'm creating a list and one of the fields
    should contain the date. Firstly I ask the user for the year, month and
    day and then I'd like to collect all this data in one field. To do this
    I tried to concatenate those 3 numbers into one using strcat. A piece
    of code is as follows

    /*function to enter the date*/
    char * date (void)
    {
    long year; /* it must of a long type */
    long month; /* because of some other reasons*/
    long day;
    char *str1;
    char *str2;
    char *str3;
    char *str4;

    /*here are the functions collecting the data from the input*/

    str1 = strcat (year,'-');
    str2 = strcat (str1, month);
    str3 = strcat (str2,'-');
    str4 = strcat (str3,day);

    return str4;
    }

    I think the result should be "year-month-day".. Why it doesn't work?

  • Ico

    #2
    Re: strcat and three strings

    alternativa <alternativa.4@ wp.pl> wrote:[color=blue]
    > I have a following problem: I'm creating a list and one of the fields
    > should contain the date. Firstly I ask the user for the year, month and
    > day and then I'd like to collect all this data in one field. To do this
    > I tried to concatenate those 3 numbers into one using strcat. A piece
    > of code is as follows
    >[/color]
    [...][color=blue]
    >
    > I think the result should be "year-month-day".. Why it doesn't work?[/color]

    My first suggestion is that you did not allocate any space for your
    data, you only defined the pointers. Please post a complete program
    instead of only a snippet.

    --
    :wq
    ^X^Cy^K^X^C^C^C ^C

    Comment

    Working...