Assume I have a program that calculates the result of multiplying two integers together from a string. I use strtol to separate the first part but how do I separate the second int? For example, "12 5" would give a result of 60.
Right now my code looks like:
int multiply(const char *input) {
int result = 0;
char *second_int;
int i = strtol(input_line, &second_int, 10);
result = i * second_int;
return result;
So obviously right now this would give an error since I only converted the first part of the string to an integer. How do I convert the leftover string into an integer? Do I need another strtol line? Do I need to cast it? I'm unsure of how to go about this.