?
Solved

Modifying a date format

Posted on 2005-03-16
5
Medium Priority
?
308 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: 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

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
Suggested Courses

752 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