Hi guys,
I got a programming assignment and I am not allowed to use 'strings' to solve this specific problem I have encountered. In this program, the user inputs a fixed length number and the program collects the number via the scanf function. I needed to break the number into segments so I used division by 10^x (x varying) and also the modulus operation. The problem I have is that when I use the modulus operation and the number contains a zero, I lose that zero. I need the zero because the number is a barcode.
For example:
Barcode: 9484029480583
If I wanted to extract the number 058 from that barcode (the last three numebrs minus the checksum) I would use the following operation:
((9484029480583)/(10))%(1000), but the problem is instead of the result being 058, I get just 58. I can overcome this problem by simply inputting a zero in front of the two numbers when using printf, but this would create extensively messy code because I would have a lot of 'if' statements (Im not allowed to use 'case' so don't go there). Is there a way that I can somehow retain that zero in front of the three number segment?