Thread: why is this function to write a matrix on a file not working? It's in C

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    2

    why is this function to write a matrix on a file not working? It's in C

    Hallo everyone! this is my first post so if I make any mistakes plase let me know..
    I am writing this program in which I generate a hilbert matrix and create it's inverse. then I manipulate these 2 matrices and obtain other ones, that I shall call M,M1, M2, etc.. at a certain point I want to save one of these matrices, say M, on a file and to do so, I have to write and independet function that is called from the main.. this is what I wrote but it's not working!! can anyone help?!

    /* function to save matrix on file */

    Code:
    void savematrix(double n, double matrix[][MaxDim])
    {
         
         int i,j;
         FIlE *f1;
         f1=fopen("matrix.txt","w");
         if (f1=NULL)
         {
                printf("file could not be opened");
                     exit(-1);
                     }
         
         for (i=0;i<n;i++)
         {
             for (j=0;j<n;j++)
             {
                 fprintf(f1,"%5.2f ", matrix[i][j]);
                 }
                 fprintf(f1,"\n");
    }
    fclose(f1);
    }

  2. #2
    Registered User
    Join Date
    Sep 2009
    Posts
    2
    ok.. I found the error:
    it shold have been:

    if (f1==NULL)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  4. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  5. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 09:51 AM