How does scanf convert the characters from stdin into an int (in this case, my integer)? I know it's possible to do this:Code:scanf("%d", &my_integer);
Is this what scanf actually does? If not, how is it implemented to handle integers?Code://Assume that read_a_string_from(stdin) exists. //Also assume that it contains nothing but a positive number; this code won't work properly for negative numbers. char* my_string = read_a_string_from(stdin); int result = 0; for (i = 0; i < strlen(my_string); ++i) { int current_digit = (int)my_string[i]; result = result*10 + current_digit; } return result;
Thank you in advance... And I hope this makes sense.