Thought I would post this here as it is the forum closest to this topic that I could find.
I'm trying to write this program for class, and I'm having trouble doing part of it.
What it needs to do is read a file and put the data into arrays. The file has 4 lines, with double variables on each line, separated by spaces (2 spaces for some reason). Each line needs to be entered into a separate array, so that there are 7 numbers in the first array, 7 in the second, 3 in the 3rd, and 3 in the fourth. He says we are supposed to use fscanf in order to read in the data, but I thought I read that it did not work with spaces. We are using loops to enter each variable, so there will be 4 loops total, 1 for each array/line.
The text file looks like:
xxxx xxxx xxxx xxx xxx xxxx xxxx xxxx xxx xxxx xxx xxx xxxx xxxx xxx xx xxx xxxx xx xxxx
Thanks for the reply, but I need to try to read in that data using for loops. I know how times each one has to iterate though, so it should be easier.
I have tried this so far:
double Tpres[NP], Psat[NP], Tsat[NH], HGsat[NH];
FILE *data;
data = fopen("me30-proj10-data.txt","r" );
if(data == NULL)
{ printf("There was an error opening the file.\n" );
That's easy (I think!). You're counting from 0 to NP (i.e. NP + 1 times) but your array only has NP elements. Classic C mistake. Try changing the "<=" to "<" in the for loops.
You are about to answer a thread that has been inactive for more than 6 months. If you still wish to proceed, please ensure that your posting is original and does not duplicate or overlap any prior responses to this thread.