I need to split an int into two ints. I have the year which I got from strptime() and need to get the first two digits into one int and the last two digits into another int. What is the method for doing so?
So year = 2007
firstDigits = 20
lastDigits = 07
The above mentioned solutions will work if you don't mind '07' being treated the same as '7'. But if you need to preserve the leading '0' then you're looking at some extra work somehow. Just something to keep in mind. It really depends on what you plan to do with the results.
As long as it is an int, leading zeroes mean nothing. If you want to output the int with a leading zero, that requires some basic formatting magic. 😉
Bah I feel like an idiot now 🙂. Thanks for the help.
As for whether strptime() already having those functions I have no idea. I'm trying to learn different parts of the standard library using http://www.gnu.org/software/libc/manual/html_node/index.html and it is not the easiest document to read for a beginner.
%C
The century of the year. This is equivalent to the greatest integer not greater than the year divided by 100.
This format was first standardized by POSIX.2-1992 and by ISO C99.
%Y
The year as a decimal number, using the Gregorian calendar. Years before the year 1 are numbered 0, -1, and so on.
You've got to learn to read documentation. Naturally, I'm not a fan of the GNU manual because it's meant to be read like a book, rather than being like an O'Reily quick reference.
Bah I feel like an idiot now 🙂. Thanks for the help.
As for whether strptime() already having those functions I have no idea. I'm trying to learn different parts of the standard library using http://www.gnu.org/software/libc/manual/html_node/index.html and it is not the easiest document to read for a beginner.
Any reason why you couldn't use sprintf() to convert the number to a string (with the leading zeroes), and then use string functions to break it apart?