0

im on the credit problem trying to use get_long to get a card number, but when i print out the result of get_long, im getting a completely different number from the one i give it.

the function looks like this

long getCardNum (void)
{
    long n;
    do
    {
        n = get_long("enter number: ");
        printf("n: %lo\n", n);
    }  

the while statement just checks that n is more than 1. If i give it "456" it gives me "710", "1357913579" gets "12074016753", and so on. cs50 docs haven't been much help trying to figure out whats happening and i haven't seen quite the same question on here. i just need to know if i'm missing something or if i just need to use some other method to get a card number. do i need to use something besides %lo in the printf call or should i use a different data type for the number? please let me know if im just missing something obvious.

1
  • I think the problem is the o in the format string, it converts the number to octal. Try u instead. FYI man printf Commented May 12, 2020 at 18:34

1 Answer 1

1

%lo says "print this in octal notation"

Try %li instead. That will print in decimal notation, as you expect.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .