-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_card_length.c
38 lines (33 loc) · 973 Bytes
/
get_card_length.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "creditcard.h"
/**
* @file get_card_length.c
* @brief Implementation of the function to get the length of a credit card number.
*/
/**
* @brief Gets the length of the credit card number.
*
* This function calculates the length of the provided credit card number by iteratively
* dividing it by 10 until the number becomes zero.
*
* @param card The credit card number.
* @return The length of the credit card number.
*/
long get_card_length(long card)
{
long count = 0;
long boolean = 1;
long test_length = card;
long whole, remainder;
// Continue the loop as long as boolean is true (non-zero).
while (boolean)
{
// Divide the test_length by 10 to get the quotient and remainder.
whole = test_length / 10;
remainder = test_length % 10;
test_length = whole;
boolean = whole;
count++;
}
// Return the calculated length of the credit card number.
return count;
}