How to get date in a particular format [duplicate] - c

This question already has answers here:
How to format date and time string in C++
(6 answers)
How to print time in format: 2009‐08‐10 18:17:54.811
(7 answers)
Closed 9 years ago.
I have been searching on the net on how to get and store the current date in yyyymmdd format. There are many code out there but it formats the dos %date%:%time% output to required specs.
The problem with that is, I need it to work universally across all regional settings. I can't find the code example to do that.
Can anyone help? If this is not possible, then is there a way to change the regional setting temporarily write the file and change it back to what it was?

Related

fortran function to find available file unit [duplicate]

This question already has answers here:
getting free unit number in fortran
(2 answers)
Closed 7 years ago.
I can write a FORTRAN function to find an available file unit, but I was certain there was already an intrinsic. But if there is, I can't find anything about it. Is there such a thing or am I dreaming?
UPDATE: Apologies for the duplicate. Did a search, but it didn't show up.
I guess, you are looking for newunit (available with F2008, shown at the bottom of that link in the Fortran Wiki).
Ups, has already been answered.
maybe you were thinking of inquire?

What is an offset in a hex dump? [duplicate]

This question already has answers here:
Can someone explain hex offsets to me?
(6 answers)
Closed 8 years ago.
I'm trying to understand what an offset in a hex dump is. In particular, what purpose does an offset serve? I have googled many times but not found anything.
The offset describes where something is in the file. You can obtain and jump to offsets in code using lseek(2) or fseek(3), depending on which I/O system you're using.

Telling when file was last accessed in C [duplicate]

This question already has an answer here:
Determining if file has been copied or not in C [closed]
(1 answer)
Closed 9 years ago.
In Windows, if you go to a file's properties it shows the last access time right under the time last modified. This changes when I copy it.
How do I view this in C?
You can use the GetFileTime() function to get it. This MSDN article has more details about file times.
The portable way of getting the last modified timestamp is by using fstat or stat. If you want to go the Windows-only route (by directly calling a Windows API), see #xxbbcc's answer.
See How can I get a file's size in C++? for a short piece of sample code that uses stat/fstat - only change for your purpose is that you'll want to read the time_t st_mtime field.

User string input show in color [duplicate]

This question already has answers here:
Color text in terminal applications in UNIX [duplicate]
(4 answers)
Closed 8 years ago.
I am using a Solaris server in my engineering course. Running code through SecureCRT and the gcc compiler. A task we have is to have the user input a string, and for the program to reverse it. The input string needs to show up in red, and I do not know what code manipulates colors to screen.
See Image for input /output
I tried running the code from the first link below, and it didnt output in any colors. It still shows all of the words in the standard black and white
Look into ncurses. It's a library built to handle this sort of thing, among other formatting.
start_color() in curses might be a good start.

Format a Large Number [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to format a number from 1123456789 to 1,123,456,789 in C?
How can I format a large integral number with commas in C, such that the readability is improved?
222222 should be 222,222 and 44444444 should be 44,444,444.
You do not need to do the formatting yourself; printf in Unix has a ' modifier:
printf("%'d\n", number);
It looks like Visual Studio doesn't support that. This syntax is locale-aware, however.
Use the modulus (%) operation and build your own string.
If you google for "c format thousands separator" then one of the hits is this page http://www.codeguru.com/forum/archive/index.php/t-402370.html
It's C++ though but it should give you an idea of what you can do.

Resources