Hey so this is frustrating the hell out of me and I don't know why it isn't working. As of right now I just want to make a basic 2 by 2 matrix. The in_file would be
2.000000000 3.00000000
6.000000000 5.00000000
So the code is as follows
#include <stdlib.h>
#include <stdio.h>
#define ELEMENTS 1
#define n 1
double Angstroms[ELEMENTS];
double Energy[ELEMENTS];
double ax[ELEMENTS][n];
void file_input ();
void polynomial ();
// void conversion ();
int main () {
file_input ();
polynomial ();
// conversion ();
return 0;
}
void file_input () {
float a, b;
int i;
FILE * in_file = fopen("H2Mini.txt", "r");
for (i = 0; i <= ELEMENTS; i++) {
fscanf(in_file, "%f %f\n", &a, &b);
Angstroms[i] = a;
Energy [i] = b;
}
fclose(in_file);
}
void polynomial () {
int i;
FILE * outfile = fopen("PolyTest1.txt", "w");
if (outfile == NULL) {
printf ("Error file does not exist");
exit (-1);
}
for (i = 0; i <=ELEMENTS; i++) {
ax[i][0] = 1;
// printf ("\n");
ax[i][1] = Angstroms[i];
fprintf (outfile, "%.8f %.8f\n", ax[i][0], ax[i][1]);
}
}
The outfile is making this
[1.00000000 2.00000000
1.00000000 1.00000000]
I want the outfile to look like this
[1.00000000 1.00000000
2.00000000 6.00000000]
I really don't understand why the outfile is looking like that so any input please let me know.