Search code examples
cmatrixfile-read

Read space separated float values of matrix from text file in C


What can be wrong with my code below that it never opens the file. I've also tried with absolute file path but that doesn't helped me, I know physically that the file is there.

FILE *myfile;


    myfile= fopen("IN.txt",r);
    if (myfile != NULL)
    {
        while ( fscanf(myfile,"%lf",&test) !=eof )
        {
            printf("%f",test);
            printf("\n");
        }
    }
    fclose(myfile);

Solution

  • myfile= fopen("IN.txt",r);
    

    schould be

    myfile = fopen("IN.txt","r");
    

    and make sure your filesystem is as case(in)sensitive as your filename suggests (so "IN.txt" is on UN*X different file to "in.txt")