I'm a bit new to C and want to understand a few things about accessing function arguments using pointers and dereferencing.
Here's my code, the whole point of the program is to use strtol
to parse a given parameter with only two digits separated by whitespaces.
int sum(const char *input){
char *input = input_line; // dereference the address passed into the function to access the string
int i; // store sum in here
char *rest; // used as second argument in strtol so that first int can be added to i
i = strtol(input, &rest, 10); // set first int in string to i
i += strtol(rest, &rest, 10); // add first and second int
return i;
}
I'm confused how to access the string parameter given because strings have a *
by the variable name, and I'm not too sure how to work around that.
Anyway, thanks.