0

Hello,

I am trying to read two floats from a file written in its first line using the below code but after compiling I always get "wrong dimnesions"
coulp please help me in that problem.
Thanks in advance.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>

int main()
{
float width,height;
FILE *ifp;
char read[300];
ifp = fopen("thirdfile.txt","r");
if(ifp == NULL)
	{
		printf("failed to open file\n");
		return 1;	
	}

	if((fscanf(ifp, "%f %f ", &width,&height)) != 2)
	
		{			
			printf("wrong dimmensions\n");
			return 1;

		}
	if ( (width < 0.00) || (height < 0.00) || ( (fmod(width,1.00)) != 0.00) || ( (fmod(height,1.00)) != 0.00) )
		{			
			printf("wrong dimmensions\n");
			return 1;

		}
fclose(ifp);
return 0;

}
2
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by Ahmed Sarwat
0

im guessing the input file what you are using has the numbers not separated from each other.

This was the contents of the file when i executed:

10.0 20.0

This works fine, so i guess the problem was, you had not separated by spaces.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.