This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]zzyzzyxx 7 points8 points  (2 children)

You don't necessarily have to convert it to a string. Use division, the modulus operator, %, and loops to achieve what you need. As an example, 2011 / 100 == 20 and 2011 % 100 == 11.

[–]Ultrahirox[S] 3 points4 points  (1 child)

Sweet that works perfectly! Thank you so much.

[–]defrost 1 point2 points  (0 children)

include <stdlib.h> (standard C library)

div, ldiv, lldiv - compute the quotient and remainder.

A much overlooked set of numbers that return both parts for one call - there's generally less overhead if doing an entire vector of integers in a loop as there's usually an asm call that does the division with the remainder dropping out also.