Weight Change Program - Help
The program is given input from a file in the following format:
A 45kg 52lb 5
B 82lb 15st 8
C 14st 80kg 10
etc..
Where A is a user identifier, 45kg is the starting weight, 52lb is the ending weight, and 5 is the numbers of days that has elapsed. (In the second line st stands for stones and is equal to 14lb).
The program must compute and output the average weight gain/loss per day in kg for each line of input. There's also a whole bunch of validation for each input but I've pretty much covered those. I know how to get the digits from each line of input and I know how to convert ASCII to int. What I don't know is how to separate the numbers from each other so I can do the conversions necessary to calculate the weight change.
What I mean by this, taking line 1 as an example:
How do I separate 45 from 52 from 5 and how do I know that its 45kg (as opposed to lb or st), and 52lb (as opposed to kg or st)?
Code:
tokenPtr = strtok( ch, "kg "" "" lb st '\t'" );
while ( tokenPtr != NULL )
{
printf( "%s\n", tokenPtr );
tokenPtr = strtok( NULL, "kg "" "" lb st '\t'" );
}
That gives the separated numbers, however I still don't know how to determine the units of the weights, or even if I'm going in the right track.
BTW 'm not permitted to use any functions other than getchar(), putchar(), printf(), and the functions from string(3).
Any help is appreciated.