Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <cs50.h>
- // declare our global vars that will be shared through out the program's functions
- int *digits;
- long cardNum;
- int firstDigit;
- int secondDigit;
- int numberOfDigits;
- int *evenIndexDigits;
- int *oddIndexDigits;
- void getInput(void)
- {
- // checks input and passes it through a validator, if is valid, return value
- cardNum = get_long("Enter a credit card number: ");
- numberOfDigits = floor(log10(cardNum));
- printf("%d\n", numberOfDigits);
- if (numberOfDigits < 13 || numberOfDigits > 16)
- {
- printf("INVALID check number size!\n");
- exit(0);
- }
- digits = calloc(numberOfDigits, sizeof(int));
- for (int i = 0; i <= numberOfDigits; i++)
- {
- digits[i] = cardNum % 10;
- cardNum /= 10;
- }
- firstDigit = digits[0];
- secondDigit = digits[1];
- }
- void parse(void)
- {
- numberOfDigits += 1;
- int evenCounter = 0;
- int oddCounter = 0;
- if (numberOfDigits % 2 == 0)
- {
- evenIndexDigits = calloc(8, sizeof(int));
- oddIndexDigits = calloc(8, sizeof(int));
- printf("if worked\n");
- }
- else
- {
- evenIndexDigits = calloc(7, sizeof(int));
- oddIndexDigits = calloc(8, sizeof(int));
- printf("else worked\n");
- }
- }
- string checkValidity(void)
- {
- return "i dont exist";
- }
- int main(void)
- {
- getInput();
- //string res = checkValidity();
- parse();
- free(digits);
- free(evenIndexDigits);
- free(oddIndexDigits);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement