开发者

Formatting a barcode with hyphens in between - Assignment question

The assignment at my first year uni computing course says my program should read a barcode number, and then display the same 13 digit barcode number separated by hyphens. For example, 9300675016902 should look like 930-067501-690-1.

The restrictions say I can't use the follow开发者_StackOverflowing:

No arrays No strings No functions.

Any directions on this?

So far I have:

part1 = barcode/10000000000;

which gives me the first three digits, and this:

part4 = barcode%10;

which gives me the last digit.

Thanks in advance!


Try:

    long p1 = n/10000000000;
    long p2 = n%100000000000/10000;
    long p3 = n%10000/10;
    long p4 = n%10;
    printf("%03ld-%06ld-%03ld-%01ld\n",p1,p2,p3,p4);


If you actually can't use strings, you're going to need to do is to go through each digit in turn and use putchar('0' + x); where x is the current digit..


I'll give you a clue, without answering your homework directly.

Bit masks.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜