I do not want the answer, I just want what I am doing wrong and hints on how to fix it.
Problem 1: You are using testscore
variable before it is being initialized.
Problem 2: You are not performing error handling with atof
. I would suggest to use strtod()
. You can perform some error handling with it to know that the third argument is a float or not. You can also create your own implementation of atof()
which will convert and report error in conversion, if any.
Hint: Try to first check that the number of arguments passed to the c program. After that, try to convert third argument to float using strtod()
or your own implementation. If it successfully converts, assign the result of float convrsion to test_score
and print last_name
and testscore
. If not, then consider third argument as last_name
and print first_name
and last_name
.