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;

}

Recommended Answers

All 2 Replies

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.

Thanks myk45
now it worked.

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.