diff --git a/cpair/cpair.c b/cpair/cpair.c index 5670225..4a548f0 100644 --- a/cpair/cpair.c +++ b/cpair/cpair.c @@ -90,14 +90,14 @@ int main(int argc, char *argv[]) { node_t * current = head; while(fgets(input, __INT8_MAX__, stdin) != NULL) { ///< Read line by line - char *sep, *end; - float x = strtof(input, &sep); ///< if no characters were converted then input will point to end - float y = strtof(sep, &end); + /// Split the input by whitespace as delimiter + char *x = strtok(input, " "); + char *y = strtok(NULL, " "); - if(input != sep || sep != end) { + if(x != NULL && y != NULL) { /// Convert to float and save to the list - current -> points[0] = x; - current -> points[1] = y; + current -> points[0] = strtof(x, NULL); + current -> points[1] = strtof(y, NULL); current -> next = malloc(sizeof(node_t)); current = current -> next; point_num++; ///< Increase the list length