Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Modifying a date format

Posted on 2005-03-16
5
Medium Priority
?
309 Views
Last Modified: 2010-04-15
int main()
{
char OldTimeFormat[] = "20050315";
char NewTimeFormat[32];

//strcpy(NewTimeFormat, OldTimeFormat+4);
//strncat(NewTimeFormat, OldTimeFormat, 4);

if (strlen(OldTimeFormat) > 4)
{
         strcpy(NewTimeFormat, OldTimeFormat+4);
      strncat(NewTimeFormat, OldTimeFormat, 4);
      printf("%s\n", NewTimeFormat);
}
}

-------------------------------------------------------------
The above code o/p converts the yyyymmdd to mmddyyyy for example with the input value of 20050315 the o/p is 03152005
how do i modify the logic to to add "/" in the o/p so that
the o/p wud be
03/15/2005
0
Comment
Question by:ronan_40060
  • 3
  • 2
5 Comments
 
LVL 8

Accepted Solution

by:
novitiate earned 1000 total points
ID: 13554986
void main()
{
      char OldTimeFormat[] = "20050315";
      char NewTimeFormat[32];
      
      int dd, mm, yyyy;
      
      sscanf(OldTimeFormat, "%4d%2d%2d", &yyyy, &mm, &dd);
      sprintf(NewTimeFormat, "%02d\\%02d\\%4d",dd, mm, yyyy);
      
      printf("%s\n", NewTimeFormat);
      
      
}

_novi_
0
 
LVL 8

Expert Comment

by:novitiate
ID: 13554992
sprintf(NewTimeFormat, "%02d\\%02d\\%4d",mm, dd, yyyy);
0
 
LVL 9

Author Comment

by:ronan_40060
ID: 13555146
Thanks a lot
I will test and get back to u
regards
Ronan
0
 
LVL 8

Expert Comment

by:novitiate
ID: 13555299
/
sprintf(NewTimeFormat, "%02d/%02d/%4d",mm, dd, yyyy);

_novi_
0
 
LVL 9

Author Comment

by:ronan_40060
ID: 13556642
Novi
Your code rocks
Thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question