hi guys i need a little hint on how to break an integer into its component
so if you have like 1567 i need to get 4 integers with 1,5,6,7. Thank you
snedan
0
Newbie Poster
Recommended Answers
Jump to Post(1567 / 1 ) % 10 = 7
(1567 / 10 ) % 10 = 6
(1567 / 100 ) % 10 = 5
(1567 / 1000) % 10 = 1See a pattern?
Jump to PostAlso you can do it with string.
len = sprintf(buff, "%d", num); for (i=0; i<len; i++) { printf("%d\n", buff[i] - '0'); }
Where num is in your case 1567.
All 6 Replies
WolfPack
491
Posting Virtuoso
Team Colleague
andor
25
Posting Whiz in Training
snedan
0
Newbie Poster
WolfPack
491
Posting Virtuoso
Team Colleague
snedan
0
Newbie Poster
~s.o.s~
2,560
Failure as a human
Team Colleague
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.