strcat problem

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

Flash Gordon

alternativa wrote:

How many times do you have to post the same thing? This is a news group
not a chat room, it can take a couple of days for people to see your
post and respond, so multiple postings just serve to annoy the people
from whom you want help.
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

You are using strcat, so include the standard header that declares it:
#include said:
/*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,'-');

<snip>

Then the compiler will bitch about the above line. Read your text book
for who strcat works. Hint, is year a pointer to a string?
 
A

alternativa

Thanks for your help and sorry for this multiplied posts :( Something
was wrong with google groups,I guess.
 
D

Default User

Flash Gordon wrote:

How many times do you have to post the same thing? This is a news
group not a chat room, it can take a couple of days for people to see
your post and respond, so multiple postings just serve to annoy the
people from whom you want help.

It should be noted that Google was hosed up over the weekend, resulting
in many problems, including extreme delay in sending messages.



Brian
 
R

Richard Bos

alternativa said:
Thanks for your help and sorry for this multiplied posts :( Something
was wrong with google groups,I guess.

Lots is wrong with Google Broken Groups, including the lack of quoting.

Richard
 
I

Ico

Default User said:
It should be noted that Google was hosed up over the weekend, resulting
in many problems, including extreme delay in sending messages.

Ok, I was not aware of that problem, my apologies to the people I flamed
today about multiple postings. (Although, using google is still a bad
excuse)

Ico
 

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

strcat problem 8
strcat and three strings 1
strcat and three strings 1
problem with strcat function 20
Taskcproblem calendar 4
Help with code plsss 0
Pascal - C (2) 57
Getting a bad input error, not sure why. 2

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top