Thread: Loading file, matrix problem C

  1. #1
    Registered User
    Join Date
    Jan 2018
    Posts
    1

    Loading file, matrix problem C

    Hello,
    I'm writing a program that is supposed to load a file with a matrix in it. The format is: the first number is always the number of unknowns, the rest are matrix numbers going from the left to the right. I have problem loading the numbers, the program always loads the number of unknowns only - the first number of the .txt file, the rest are zeros.
    Code:
        int i = 0;
                int u = 0;
                int probehl = 0;
                float x = 7;
    
    
                file = fopen("matica.txt", "r");
    
    
                if (file != NULL)
                {
                    fscanf(file, "%d", &unknown);
    
    
                    printf("Number of unknowns: %d\n", unknown);
                    do
                    {
                        probehl++;
                        fscanf(file, "%d", &x);
                        printf("[cislo: %d]%f ", probehl, x);
                        A[i][u] = x;
    
    
                        u++;
                        if (u > unknown)
                        {
                            u = 0;
                            i++;
                        }
                    }
    I would appreciate any help. I am very bad at coding... Also I am sorry for my English.

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,465
    Also posted here.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem in loading file into program..
    By nyekknyakk in forum C Programming
    Replies: 3
    Last Post: 09-23-2010, 11:23 AM
  2. Problem with loading a file
    By ManiacBR in forum C++ Programming
    Replies: 2
    Last Post: 12-11-2006, 04:55 PM
  3. Replies: 6
    Last Post: 03-06-2005, 02:43 PM
  4. Problem loading file...URGENT
    By khpuce in forum C Programming
    Replies: 4
    Last Post: 05-19-2003, 08:14 AM

Tags for this Thread