I have been working on this code for a while and I can't seem to get to work right. I have been trying to make a credit card validator program in c for a class assignment. Any help would be welcome.

``````#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

void checkCard( long x, long *s );

int main ()
{
//define variables for the data
long *s;
long x, i;

malloc(sizeof(x));
//ask user to enter a credit card number as a long int. Number must have between 13-16 digits. It must start with 4 for Visa cards,
//5 for Master cards, 37 for American Express cards, or 6 for Discover cards
//store the data that the user entered
//call to array containing the credit card check function
//print for the user whether the credit card number is valid or invalid
printf( "Enter a credit card number as a long integer: \n" );
scanf( "%ld", x );
checkCard( x, s );

return 0;
}

void checkCard( long x, long *s )
{
long S1, S2, Sum;
//Step 1: Double every second digit from right to left. If doubling of a digit results in a two-digit number, add up the two digits to get a single digit number.
x = x * 2;

if ( x > 9 ) {
x = x - 9;
}

x = x * 2;

if ( x > 9 ) {
x = x - 9;
}

x = x * 2;

if ( x > 9 ) {
x = x - 9;
}

x = x * 2;

if ( x > 9 ) {
x = x - 9;
}

x = x * 2;

if ( x > 9 ) {
x = x - 9;
}

x = x * 2;

if ( x > 9 ) {
x = x - 9;
}

x = x * 2;

if ( x > 9 ) {
x = x - 9;
}

x = x * 2;

if ( x > 9 ) {
x = x - 9;
}
//Step 2: Now add all single-digit numbers from Step 1.
S1 = x + x + x + x + x + x + x + x;
//Step 3: Add all digits in the odd places from right to left in the card number.
S2 = x + x + x + x + x + x + x + x;
//Step 4: Sum the results from Step 2 and Step 3.
Sum = S1 + S2 - 48;
//Step 5: If the result from Step 4 is divisible by 10, the card number is valid; otherwise, it is invalid.
if ( Sum % 10 == 0 ) {
printf( "%ld is valid.\n", *x );
} else {
printf( "%ld is invalid.\n", *x );
}
exit(main());
}``````