473,472 Members | 2,193 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to combine string

Dear all,
I want to create file, of which name is [current date+".log"].
But i do not know how to do. My sample code is shown as bellow:

... sprintf(buf2,"%d/%d/%d %d:%d:%d",
tims->tm_mon+1,
tims->tm_mday,
tims->tm_year+1900,
tims->tm_hour,
tims->tm_min,
tims->tm_sec);

f=fopen(buf2,"a"); /* open log */->will create file "2003-10-27"

But i want to create file, "2003-10-27.log".
Can anyone teach me how to do?
Nov 13 '05 #1
4 5572
fr********@qdi.com.tw (Frank Hung) writes:
Dear all,
I want to create file, of which name is [current date+".log"].
But i do not know how to do. My sample code is shown as bellow:

... sprintf(buf2,"%d/%d/%d %d:%d:%d",
tims->tm_mon+1,
tims->tm_mday,
tims->tm_year+1900,
tims->tm_hour,
tims->tm_min,
tims->tm_sec);
See strftime in <time.h>.
f=fopen(buf2,"a"); /* open log */->will create file "2003-10-27"
But i want to create file, "2003-10-27.log".


You can strcpy ".log" to buf2 before calling fopen.
Nov 13 '05 #2
"Frank Hung" <fr********@qdi.com.tw> wrote in message
news:e3**************************@posting.google.c om...
Dear all,
I want to create file, of which name is [current date+".log"].
But i do not know how to do. My sample code is shown as bellow:

... sprintf(buf2,"%d/%d/%d %d:%d:%d",
tims->tm_mon+1,
tims->tm_mday,
tims->tm_year+1900,
tims->tm_hour,
tims->tm_min,
tims->tm_sec);

f=fopen(buf2,"a"); /* open log */->will create file "2003-10-27"
Not according to the format in the sprintf call.
But i want to create file, "2003-10-27.log".
Can anyone teach me how to do?


Just specify the appropriate format in the call to sprintf:

sprintf(buf2, "%4d-%02d-%02d.log", tims->tm_year + 1900,
tims->tm_mon + 1, tims->tm_mday);
f = fopen(buf2, "a");

Better still, use strftime() in much the same way.
Nov 13 '05 #3
Thomas Pfaff <th**********@tiscali.no> wrote:
fr********@qdi.com.tw (Frank Hung) writes:
Dear all,
I want to create file, of which name is [current date+".log"].
But i do not know how to do. My sample code is shown as bellow:

... sprintf(buf2,"%d/%d/%d %d:%d:%d",
tims->tm_mon+1,
tims->tm_mday,
tims->tm_year+1900,
tims->tm_hour,
tims->tm_min,
tims->tm_sec);


See strftime in <time.h>.
f=fopen(buf2,"a"); /* open log */->will create file "2003-10-27"
But i want to create file, "2003-10-27.log".


You can strcpy ".log" to buf2 before calling fopen.


Better use strcat. ;-)
Or append ".log" to the sprintf format string.

Regards
--
Irrwahn
(ir*******@freenet.de)
Nov 13 '05 #4
Irrwahn Grausewitz <ir*******@freenet.de> writes:
Thomas Pfaff <th**********@tiscali.no> wrote:
You can strcpy ".log" to buf2 before calling fopen.


Better use strcat. ;-)


Since strftime returns the number of characters written to the destination,
you might aswell use strcpy and save the time needed to discover something
you already know.

But I won't claim this is what I had in mind in my first post. I did mean
to write strcat ;-) Thanks.
Nov 13 '05 #5

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

Similar topics

3
by: mmccaws | last post by:
Thanks ahead for your help I'm trying to learn what I can do with echo and print statements. I figured out the echo statement and below is the simple version using print. I've tried two dozen...
4
by: MichaelD | last post by:
Hi! How do I combine an element pattern with attributes? I can validate <phone>111-111-1111</phone> using pattern
8
by: mark | last post by:
Access2000 How do I write a query that combines the CTC field from each record below into one record? I need to concatenate the CTC field with a separator, like below: ...
4
by: PZWU | last post by:
How can I build a big XML file by appending a few smaller xml files in C#? Below is what I've been trying: /* FileString.xml is the path and name string of the big xml file*/ XmlTextWriter...
1
by: William Stacey [MVP] | last post by:
I need a bullet proof way to combine a root and a relative path to form a FQ rooted path (similar to a VDir in IIS). Path.Combine alone will not do the job in all cases. I also need to be sure...
3
by: steve_h | last post by:
I think the subject says it all, but just in case: I know that I can call my own methods during an XSL transformation using <xsl:value-of select="myObject.someMethod(arg1)" /> having done...
8
by: frekster | last post by:
Hi. I used to be able to do this easily in vb 6 via looping and preserving the source array data/size etc. How can I do this in vb.net? I've been trying for a while now and this should be...
6
by: :) | last post by:
How to combine serveral large .txt files in C# without using MS command line. Thanks!!
15
by: d4 | last post by:
I have a vbscript (below) I want to rewrite in C# but I cannot get it to work (unless there is a better way to do it). The script will combine 2 lines if the (next) line contains a "+",...
3
by: Steven Bethard | last post by:
Within a larger pyparsing grammar, I have something that looks like:: wsj/00/wsj_0003.mrg When parsing this, I'd like to keep around both the full string, and the AAA_NNNN substring of it, so...
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.