0

So I have this char array taken from a .txt file (a matrix exactly) and I'm trying to covert it to a floating point two-dimensional array.

char c[MAX]="";
int x=0;
float **mat;

scanf ("%s", name);
FILE* f=fopen(name, "r+");

for (int p=0; !feof(f); p++){
    c[p] = fgetc(f);
    if (isdigit(c[p])) x++;
}
for (int z=0; z<2*x; z++){
    for (int i=0; i<x/2; i++){
        for (int j=0; j<x/2; j++){
            if (isdigit(c[z])) 
                c[z]=(float)atof(mat[i][j]);
        }
    }
}

All I get is that the .exe file is not responding. I know it's because I'm not doing it right

Wasi Ahmad
  • 35,739
  • 32
  • 114
  • 161
Daniel Zaksevski
  • 68
  • 1
  • 2
  • 8
  • 2
    First thing when you open a file is to check that it did open. Without that the rest is useless. – Weather Vane Nov 16 '16 at 18:16
  • 1
    Please post the [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) that shows the problem. Show an example input, the expected output, and the actual output. Also, please see [Why is “while ( !feof (file) )” always wrong?](http://stackoverflow.com/questions/5431941/why-is-while-feof-file-always-wrong). – Weather Vane Nov 16 '16 at 18:22
  • I guess the problem is in - **mat. How "c[z]=(float)atof(mat[i][j]);" this statement would work?? – Wasi Ahmad Nov 16 '16 at 18:27
  • 1. Yes I checked if it opens correctly just didn't include it 2. I will read, thank you. 3. Yes I can think of that myself, I'm asking how to fix that – Daniel Zaksevski Nov 16 '16 at 18:31
  • You did not allocate any memory for the pointer `mat` to point to – M.M Nov 16 '16 at 20:46
  • It would help if you show an example of the file contents – M.M Nov 16 '16 at 20:49

0 Answers0