Reading a text file

I am just starting off with C++ and I am very lost! I have to read a dat file that has rows of numbers in four different columns. I just don't understand how it will read the next line of information from the data file. Could you please explain, this book is so confusing to understand.

int main()
{

	float A,B,C,D;
	FILE *testing;

	testing=fopen("testing.dat","r");
	fscanf(testing,"%f %f %f %f",&A,&B,&C,&D);



return EXIT_SUCCESS;
Is your book C or C++? If it is the later and it's using FILE, it's probably not a good book. You should use the standard library class, ifstream:

http://cplusplus.com/reference/iostream/ifstream/
My book is for C, sorry about that.
I really need help just reading the next line of a data file. No one can help? I have the first line reading just fine, but I am not sure how to setup a while loop to continue the process, I am a noob!

int main()
{

	float A, B,C,D;
	FILE *testing;

	suture=fopen("testing.dat","r");
	
	do
{ 

fscanf(testing,"%f %f %f %f",&A,&B,&C,&D);
printf("The Values of the data are:%f,%f,%f,%f \n", A, B, C, D);


}while (testing !=0, 0, 0, 0);



return EXIT_SUCCESS;

}



I am stumped on what to do next, the program wont read the next line
As far as I know all data files are read in as one line, if you want to read out the data on multiple lines you can use 2-D arrays.
Topic archived. No new replies allowed.