Thread: ReadData txt file

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Banned
    Join Date
    Apr 2015
    Posts
    596

    ReadData txt file

    Hi ! I'm struggling this problem and I didn't find a solution for it.
    I'm trying to read data from txt which the data of the txt file is about having size of matrix and coordination (x,y) according to the size where the value "1" located. it might have more than matrix on the same txt file. for example"
    Code:
    444
    12
    23
    33
    555
    12
    23
    33
    44
    the size of the matrix is always signed as 3 digits,
    for example in the first line of txt file there's 444, it says that the matrix size of matrix 4*4 and the value number one is located on matrix at coordination: 12 23 33
    for second matrix which it's in size 5 as shown in fifth line in txt file 555, the value of number one in that matrix is located at coordination: 12 23 33 44 .

    the output is to print all the matrixs that txt file input have with proper value as written in txt file.

    I'm stuck in and not moving forward , How can I assign matrixs by coordination that are given in txt file? thanks alot!!

    I've written this code for reading data from txt file but didn't work well!(wrong output)

    Code:
    int main()
    {
        int i,j;
        double value[10000][10000];
        FILE *archivo;
        archivo = fopen("matrix.txt","r");
        if (archivo == NULL)
            exit(1);
        i=0;
        while (feof(archivo) == 0)
        {
            fscanf( archivo, "%lf %lf %lf", &value[i][0],&value[i][1],&value[i][2]);
            printf("%10.0f %f %f\n", value[i][0], value[i][1], value[i][2]);
            i++;
        }
    
    
        printf("My matrix:\n");
        for(j = 0; j < i; j++)
            printf("%10.0f %10.3f %10.3f\n", value[j][0], value[j][1], value[j][2]);
    
    
        fclose(archivo);
        return 0;
    }

    THANKS for your help !
    Last edited by RyanC; 05-04-2019 at 06:47 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 11-21-2017, 10:48 AM
  2. Replies: 6
    Last Post: 12-28-2015, 03:36 AM
  3. Replies: 3
    Last Post: 11-28-2012, 09:16 AM
  4. Replies: 11
    Last Post: 09-25-2011, 12:22 AM
  5. Replies: 4
    Last Post: 07-06-2006, 02:53 AM

Tags for this Thread