How do u scan a floating number from a file?

fscanf(FilePointer, "%f", &variableName);

All the scanf() family of functions are subject to quitting the first time they receive data that they aren't set up to handle. It's important to check their return value to see if it actually worked or not, (it returns the number of items it has successfully handled), and it should only be used on data that is FORMATTED properly. Data that variies from one week to the next, is not a good candidate for fscanf().

commented: well said +6

Depends on whether its of type float or double. Floats are "%f" but doubles are "%lf". I think long doubles would be "llf", which is a little like long long int (64-bit integers).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.