So I think this should be pretty straight forward. I actually can't even understand what could possibly be going wrong, and that's what bugs me the most.
Here's the deal: I have to read a couple of numbers from a file, but these numbers are in scientific notation. An example file would have the numbers like this:
fscanf(arquivo, " %lf%*c%d%*c", &mantissa1, &expoente1);
x[i] = numToFloat(mantissa1, expoente1);
fscanf(arquivo, "%lf%*c%d", &mantissa2, &expoente2);
fx[i] = numToFloat(mantissa2, expoente2);
First, you do not need to parse the mantissa and exponent separately.
scanf natively understands
n.nnnE±nnn notation. This is why your format string doesn't behave as you expect; the
%lf directive consumes the entire first number including the
E+00 piece, then
%*c consumes the comma,
2, and now we're hopelessly out of sync.
Second, you should not use any of the
scanf functions, ever. Instead, read a line at a time with
getline, if you have it), split it on commas with
strtok, and convert numbers to binary with
strtod (which also natively understands scientific notation). This will be more coding up front, but the result will be easier to read and debug, it will be easier to make it robust against malformed input, and it will have well-defined behavior on input overflow.
(Technically you do not need to use
strtod will tell you where each number ends, but it is conceptually simpler to do the splitting first.)