strcat and three strings

A

alternativa

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?
 
I

Ico

alternativa said:
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
[...]

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

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,197
Latest member
ScottChare

Latest Threads

Top