I'm trying to do the credit card exercise for cs50. Why is it that when I store the credit card number as a variable called 'number' and then immediately print that variable, a random number is printed and not my entered credit card number?
#include <cs50.h>
#include <stdio.h>
int main(void)
{
long number = get_long("Number: ");
printf("%lo\n",number);
}
I am prompted to enter the number and put in 1234567890123
Number: 1234567890123
But the number below is what comes out
21756176602313
CodePudding user response:
The correct format specifier to print long
in decimal (base 10) is %ld
or %li
.
CodePudding user response:
The format specifier outputs in octal format:
printf("%lo\n",number);//%lo = unsigned long integer printed in octal digits.
^^
for base 10 it should be:
printf("%ld\n",number);//"%li" is also valid.
^^