0

Hi

How do I go about reading from a file (Input_image.txt) that contains a 2-D (50 by 100 = 5000 elements) array?

E.g.

000 004 567 034 ...
001 046 923 987 ...
004 345 003 745 ...
034 870 003 805 ...
054 345 025 545 ...

Each the spaces seperate with element.

My flaw code in question

void Data_Manu_Proc()
    {
        myFile = fopen("Input_image.txt","r");

        for (i=0; i<50; i++)
        {
            for (j=0; j<100; j++)
            {
                fscanf(myFile,"%03d", &image_read[50][100]);
            }

        fclose(myFile);
        }
    }
3
Contributors
3
Replies
29
Views
4 Years
Discussion Span
Last Post by Ancient Dragon
0

Looks like it should work. Except you only need "%d" instead of "%03d" because internally integers don't have leading 0's like you see them printed out. If you want to print out the number then use "%03d"

Edited by Ancient Dragon

1

line 9: You're trying to read everything into the same address space - &image_read[50][100]
Try changing it to - fscanf(myFile,"%d", &image_read[i][j]);

Votes + Comments
Good Catch :P)
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.