c – Transformed and stored reversed order digits of an integer to a complete integer number


The indentation of your post is very bad, mainly because it is very inconsistent. Run your code through a program that indents the code for you, like indent or ClangFormat.

There is a simpler solution that is also more efficient, by avoiding the first pass over all the digits to find the length of the number. The solution could be a single loop that does this:

while (number != 0) {
    // Step 1: pop last digit from number
    ...

    // Step 2: push the digit to the back of complete_integer
    ...
}

Doing this will result in the order of the digits to be reversed. You already implemented popping the last digit from a number, now try to implement the reverse operation of pushing something to the back of a number, without having to know the exact length of that number.

I wonder why you don’t allow the number 0 to be reversed. It seems that this has a clear answer. You should be able to handle that case without having to write any additional code.

For negative numbers, you could indeed disallow them, or instead define how a negative number will be reversed. For example, you could say that the reverse of the number -123 will be -321, and then ensure your code implements this case. If the requirements for this project don’t say anything about negative numbers, it is up to you.

It is good to have descriptive names for functions and variables. One-letter names are usually bad, unless it’s for very commonly used things such as i for a loop iterator, or x and y for coordinates. But too long names can be bad as well; they require more typing, and they are distracting. Not only try to be clear, also be concise. For example:

int find_out_the_reverse_order_and_transform_digits_as_a_complete_integer(int number,int value){
    ...
}

That’s a lot of text! Now compare the following:

int reverse_digits(int number) {
    ...
}

The name of this function, along with the type of the input parameters and return value, are still very descriptive; it tells you that if you give it a number as a parameter, the function will reverse the digits, and returns the result as an interger. The name is much more concise though.

Similarly, even though you shouldn’t need this function, find_out_the_number_of_digit() could be shortened to count_digits().

On the other hand, also be aware of using too similar names. For example:

int number=get_input_validation();
int value=find_out_the_number_of_digit(number);

Now you have two variables, number and value. Now I have to look at what function was called to find out that value is actually the number of digits in number. Here is a suggestion for renaming it:

int input = get_input();
int digits_in_input = count_digits(input);