K&R C Programs Exercise 4-2

Exercise 4-2. Extend atof to handle scientific notation of the form 123.45e-6 where a floating-point number may be followed by e or E and an optionally signed exponent. The K&R atof in Section 4.2 handles sign, integer part, and fractional part. Scientific notation adds a third stage: after the mantissa, look for e or E, …

C Program to demonstrate the ‘atof’ and ‘gets’ functions.

Converting strings to numbers is a fundamental task in C — every value read from scanf, fgets, or command-line arguments arrives as a string and must be explicitly converted. The standard library in <stdlib.h> provides three simple conversion functions: atoi() (string to int), atol() (string to long), and atof() (string to double/float). For robust error …