Converting a part of a string to int

Mikey, to parse your string arguments take a look at this topic. Once you have your substrings, you can convert them to integer using the atoi() command as follows:

atoi(char * p);  where char * p is the pointer to your array of chars to convert

In the topic I refer to, the strtok() function is used for parsing the string using a seperator which in your case is “-”. For each field parsed, p points to the parsed char array so to get the integer value you would use:

val = atoi(p);

Le me know how it goes! :smile:

1 Like