I have a unit conversion program that needs to take in a float and 2 strings from standard input. My previous solution was:
float orig_quant;
char *orig_name = (char*) malloc(MAX_CHARS);
char *new_name = (char*) malloc(MAX_CHARS);
fscanf(stdin, "%f %s %s", &orig_quant, orig_name, new_name);
However, this only works if the input looks like
2.54 centimeters inches
A requirement for the project is that the input looks like this
2.54, centimeters, inches
I tried to change my fscanf to something like fscanf(stdin, "%f, %s, %s"...) but that didn't work. What is the easiest way I can get rid of those commas without having to read everything in character-by-character? Should I put the whole thing in a string to start and then search for the commas and remove them? Or is there a built-in function that can help me do this automatically?
Thanks,
Ross