Thursday, July 30, 2009

How do I edit this string in C++?

This is the code:





time_t rawtime;


struct tm * timeinfo;


time ( %26amp;rawtime );


timeinfo = localtime ( %26amp;rawtime );





It is now set as follow:


Www Mmm dd hh:mm:ss yyyy





I want to leave only this way:





Mmm_dd





How do I do it?

How do I edit this string in C++?
to do this,use the strftime() function available in time.h





this function creates a string time out of the tm struct and allows you to specify the format of the time.


You can check out how to specify the format in the help of your compiler, and if you dont find out how, email me personally( I have left that unblocked ).





Yours


Harry Bazeegar
Reply:This is the code:





time_t rawtime;


struct tm * timeinfo;


time ( %26amp;rawtime );


timeinfo = localtime ( %26amp;rawtime );





It is now set as follow:


Www Mmm dd hh:mm:ss yyyy





I want to leave only this way:





Mmm_dd





How do I do it?
Reply:are you azeri?
Reply:I'd suggest you pull the month and day data out of the tm structure. You'll have to convert the numeric month to a 3-letter month abbreviation using either indexing into a string ("JanFebMar...") or create an array of strings containing the month abbreviations. If you do the latter then you can easily get the form you want using and sprintf with field qualifiers to limit size.


No comments:

Post a Comment