This was an exam question a few years ago, and I am struggling to solve it.
I have to build a program that reads from a text file a set of number, with a space in between, that could either be integers or floats. Then it prints the number with the maximum number of digits in it using a recursive function.
I don't know how to read the numbers from the file. If I read them all like floats they end up with the same amount of digits. Here's my code until know, but I don't know how to proceed. For example:
In the text file we have the numbers: 1 2 1.5 1.456 2 2.78 7
The number with the maximum number of digits is 1.456 with 4 digits in it.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n,i,nr=0;
float v[100];
FILE *fp;
fp = fopen("text.txt","r");
while(fscanf(fp,"%f",&v[nr])==1){
nr++;
}
fclose(fp);
return 0;
}