473,385 Members | 2,162 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

strcat and three strings

Hello,
I'm dealing with a problem concerning strcat.. I would like to
concatenate 3 strings, which in fact are integer numbers.

My idea is to write something like this:
void main (void);
{
long year; /*they must be of a long type because of */
long month; /*some other reasons*/
long day;
char *str1;
char *str2;

/*here I have functions asking for the data - year, month, day*/

str1 = strcat (year,month);
str2 = strcat (str1,day);
}

So for input:
2005
01
07
I'd like to get: 20050107.
Do you think it would be possible to obtain 2005-01-07? I guess I'd
need to concanate also the year with '-', then 'year-' with 'month',
and the same with day, so I get 'year-month-day'.
thanks,
a.

Jan 9 '06 #1
1 6252
alternativa wrote:
Hello,
I'm dealing with a problem concerning strcat.. I would like to
concatenate 3 strings, which in fact are integer numbers.

My idea is to write something like this:
void main (void);
{
long year; /*they must be of a long type because of */
long month; /*some other reasons*/
long day;
char *str1;
char *str2;

/*here I have functions asking for the data - year, month, day*/

str1 = strcat (year,month);
You need some other function besides strcat(), which you know if you
had checked its specs. It doesn't take longs, it takes pointers to
existing strings.

So for input:
2005
01
07
I'd like to get: 20050107.
Do you think it would be possible to obtain 2005-01-07? I guess I'd
need to concanate also the year with '-', then 'year-' with 'month',
and the same with day, so I get 'year-month-day'.
thanks,
a.


Forget concatenation. What you need is a formatted output function that
writes to strings. Happily there is one, sprintf().

Example:

/* this string is long enough to hold the described values. You should
check that the values fall with valid ranges before trying to format
the string, otherwise undefined behavior may result!!! */

char str[11];

sprintf(str, "%ld-%02ld-%02ld", year, month, day);
Brian
--
Please quote enough of the previous message for context. To do so from
Google, click "show options" and use the Reply shown in the expanded
header.
Jan 9 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: lawrence | last post by:
"Garp" <garp7@no7.blueyonder.co.uk> wrote in message news:<_vpuc.1424$j_3.13346038@news-text.cableinet.net>... > "lawrence" <lkrubner@geocities.com> wrote in message >...
7
by: news.hku.hk | last post by:
is there any way to make a loop to store strings?? e.g. abc.txt contains 3 lines i.e. this is line 1. this is line 2. this is line 3. i want to create a loop that can make the three strings...
7
by: Gaijinco | last post by:
Every information about strings seems to be very confusing! I need a program to read 3 different strings, one after the other all of them of unknown size. All the strings are separated by and...
2
by: VMI | last post by:
In my datatable, I'm retrieving three fields from an Access table and I concatenate them into one string. Then I put this information in another datacolumn that I added to the datatable (with...
1
by: alternativa | last post by:
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...
87
by: Robert Seacord | last post by:
The SEI has published CMU/SEI-2006-TR-006 "Specifications for Managed Strings" and released a "proof-of-concept" implementation of the managed string library. The specification, source code for...
5
by: Mr. Ken | last post by:
In my function, my main calls a function to save the data. In script-based languages like matlab, I can use multiple in strcat. However, in C++ it's not working since first argument of strcat...
4
by: ultragc | last post by:
Hi all. I am starting on javascript and need some help. Basically, I have a form in which I need to compare three text fields (string1, string2, and string3). The user must enter the exact text on...
4
by: techusky | last post by:
I am making a website for a newspaper, and I am having difficulty figuring out how to take a string (the body of an article) and break it up into three new strings so that I can display them in the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.