I got this code here, i wonder why it doesnt put in the file "in.dat" in the same folder.
#include <stdio.h>
#include <stdlib.h>
#define N 20 //Number of trials
void main(void)
{
FILE * pFile;
float data[N][2];
int i,j ;
char overwrite;
for(i=0;i <= N ; i++) /* Initinalize the array */
{
for (j=0; j <= 1; j++)
data[i][j]= 0;
}
for(i=0; i<=N ; ++i)
{
printf("%d %5f %5f\n", i, data[i][0], data[i][1]);
}
data[0][1] = -0.545 ;
data[1][1] = 0 ;
data[2][1] = 0 ;
data[3][1] = 0 ;
data[4][1] = 0 ;
data[5][1] = 0 ;
data[6][1] = 0 ;
data[7][1] = 0 ;
data[8][1] = 0 ;
data[9][1] = 0 ;
data[10][1] = 0 ;
data[11][1] = 0 ;
data[12][1] = 0 ;
data[13][1] = 0 ;
data[14][1] = 0 ;
data[15][1] = 0 ;
data[16][1] = 0 ;
data[17][1] = 0 ;
data[18][1] = 0 ;
data[19][1] = 0 ;
data[20][1] = 0 ;
pFile= fopen("C:\\Documents and Settings\\<snipped name>\\My Documents\\Uni Stuff\\Eng Computing\\Sourcecodes\\in.dat","rb");
for(i=0; i<=N; i++)
{
//value[i] = ftell(pFile);
data[i][0] = 5*i;
printf("%f %f\n", data[i][0], data [i][1]);
fprintf(pFile,"%f %f\n", data[i][0], data [i][1]);
}
fclose(pFile);
scanf( "%c", &overwrite);
}
2. Im trying to do this(as said in the assignment):
- Type in the experimental data in a text file and save the file as “in.dat”.
- In the data entry part, use the fscanf() function to read the data from “ïn.dat" file. It is very important that you store the data in a suitable array ( data[N][2] for example). Make sure that all the array's elements are set to zero before you use the array.
This is what i need to put in the file:
0 -0.545
5 0.462
10 2.163
15 4.446
20 7.304
25 10.781
30 14.962
35 19.613
40 25.034
45 30.882
50 37.558
55 44.505
60 52.241
65 60.568
70 69.435
75 78.947
80 89.156
85 99.876
90 111.294
95 123.2
100 135.618
Thanks for helps guys :( I really need it ><