0

I'm trying to write a simple code to read in a .PGM file. The code I wrote is

#include "./netpbm/lib/pgm.h"
#include <stdio.h>

typedef unsigned int gray;

int main(int argc, char* argv[]){

    gray Maxval;
    gray* Img[];
    int row, col;

    FILE *fp;

    fp = fopen("barcode.PGM", "r");

    pm_proginit(0, &argv[0]);

    &Img[0] = pgm_readpgm(fp, &col, &row, &Maxval);
}

it outputs error: storage size of 'Img' isn't known

any debugging suggestions?

melpomene
  • 84,125
  • 8
  • 85
  • 148

3 Answers3

1

From the documentation of libpgm, it seems like you should declare a pointer-to-pointer:

gray **Img;
...
Img = pgm_readpgm(fp, &col, &row, &Maxval);
...
pgm_freearray(Img, row);
Alok Singhal
  • 93,253
  • 21
  • 125
  • 158
0

You need to give that array a size:

gray *Img[100];

Since it looks like you won't know what size to give it until later in the program, you might want to look into dynamic allocation (using malloc(3) and free(3)) or possibly a variable-length array, if you can use C99 features.

Carl Norum
  • 219,201
  • 40
  • 422
  • 469
0

There's nothing to debug because your code doesn't even compile. It doesn't compile because you're declaring Img as an array of pointers to gray but without specifying a size. Thus the compiler doesn't know how big the array is supposed to be and complains.

melpomene
  • 84,125
  • 8
  • 85
  • 148