+ 2

C++ - Parsing an input

I'm approaching the "Calculate the distance" assignment. Problem is: given in a row coordinates of two points, in the form: (x1,y1) (x2,y2) extract in four integer variables x1, y1, x2, y2. Pattern is: points are enclosed in parentheses, they're separed by a comma, there's one or more spaces between parentheses, there can be or not a space before y1 and y2, all four integers x1, y1, x2, y2 can be positive or negative. What is the quickest way to extract x1, y1, x2, y2?

9th Aug 2019, 7:31 AM
Paolo De Nictolis
Paolo De Nictolis - avatar
1 Answer
+ 4
if they are saved as strings, what i would do (some sort of pseudocode): use a variable to store both values in a string separated by a space (lets say var) while (not the end of string) if ( "(" || ")" ) increment if ( "," || whitespace) append space to var increment var += character increment another while to store info from string var into other variables in the format that you need. don't know if it easy, it is how i would approach it.
9th Aug 2019, 7:45 AM
notqueued
notqueued - avatar