You are here:

C/convert file date/time from conventional format to DOS format

Advertisement


Question

I've accessed information about files on my machine using a linked list created using C language code.  Information is file names, size, dates and time.  The file dates and times are in 16-bit DOS format. I wrote a C code to convert the date and time to conventional format(using bit mask and right shift). eg. DOS date formats 12367 and 11341, were converted to conventional date formats 15 feb 2004 and 13 february 2002 respectively.  DOS time formats 5604 and 24909 were converted to conventional time formats 2:41:4 and 12:8:13 respectively.  However I cannot figure out how to do the reverse, ie. convert from conventional date and time to DOS format. I figured how to convert the first date from conventional to DOS but the algorithm did not work with the other values.
Thanks for your help in doing this conversion.


Answer
Before going ahead with writing the program, you must understand the problem fully.
So, create few test cases and solve them manually.
By this you will understand what is the input, what is the output and how to get the desired output.
Since you know the steps clearly, you can anticipate the results in intermediate steps and see if it is doing everything correctly.
So, in this case (Convert from conventional date/time to DOS format) also, you will have to do the same.
Take some examples of conventional date/time. forget the program that you written and convert these date/time to DOS format manually. After that go into the progam and solve.
Since, I don't have your program and also I don't know the exact formats, I will not be able to tell you where you went wrong.

Hope this helps.
If you can give me the code, sample input and output and also the formula which does the conversion, I will try to debug and give solution.

-ssnkumar

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Narendra

Expertise

I can answer questions in C related to programming, data structures, pointers and file manipulation. I use Solaris for doing C code and if you have questions related to C programming on Solaris, I will be able to help better.

Experience

6.5

Organizations belong to
Sun Microsystems

Awards and Honors
Brain Bench Certified Expert C programmer.
Advanced System Software Certified

©2012 About.com, a part of The New York Times Company. All rights reserved.