I know this sounds like a homework problem, but it's honestly not one. I am writing some code which given an IP address in string format will calculate the integer value of it. Now the trick is I need it to be quick. I see two paths and not sure which would be faster.
1) Use strtok like functionality (actually custom code to make it reentrant and in my case I can change the string) to parse the components of the address. I would also keep a count of the components for error checking.
2) Use sscanf (ip_addr_str, "%d.%d.%d.%d", &c1, &c2, &c3, &c4) and then check the return value to ensure proper formatting (ie 4 components).
Any ides which would be quicker? Any other ideas? My next step is to experiment but was hoping someone could help me avoid writing code multiple times to play with.