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);
        }
    }

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"

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]);

commented: Good Catch :P) +14

You're trying to read everything into the same address space -

Oops! I missed that one.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.