I am trying to obtain a long number, count how many digits it is, then take the 2nd last digit of that number and multiply it by 2, then iterate through the rest of the number multiplying each 2nd and then adding it to an array. It is the credit card problem set from cs50 if you guys know what I'm talking about.
When I make the program it throws back this error:
error: format specifies type 'long' but the argument has type '<dependent type>' [-Werror,-Wformat]
credit.c:22:21: error: use of undeclared identifier 'array'
printf("%ld\n", array);
^
credit.c:40:8: error: incompatible pointer to integer conversion returning 'long [nDigits]' from a function with result type 'long' [-Werror,-Wint-conversion]
return array;
^~~~~
3 errors generated.
make: *** [credit] Error 1
Code:
#include <cs50.h>
#include <stdio.h>
#include <math.h>
long find_2ndlast_nums(long x);
int main(void)
{
long n;
long nDigits;
do
{
n = get_long_long("Please enter your credit card number:\n");
nDigits = floor(log10(labs(n))) + 1;
}
while (nDigits < 13 || nDigits > 16);
find_2ndlast_nums(n);
printf("%ld\n", array);
}
long find_2ndlast_nums(long x)
{
long nDigits = floor(log10(labs(x))) + 1;
long array[nDigits];
for (int y = 1; y < nDigits; y += 2)
{
x = (fmod((floor(x / 10 ^ y)), 10)) * 2;
array[nDigits - y] = x;
}
return array;
}