0

I am reading in a PPM file, and I have used printf's throughout the function to see if it will print but for some reason it prints the p3/comment/width/height/maxcolor but it wont print the pixels... I tried checking via using printf statements inside and outside my nested for loops but it wont read in the data...Any ideas??

void ReadImages(struct ImageType *imgur, struct ImageType *imgur2)
   {
     int i=0, j=0;
     char filename[30];
     char filename2[30];

     FILE *inputfile;
     fprintf(stdout, "Please enter the filename/location of the first image\n");
     fscanf(stdin, "%s", filename);
     inputfile = fopen(filename, "r");

     fscanf(inputfile,"%[^\n]%c", imgur->ppImage, &imgur->newlinechar);
     fscanf(inputfile,"%[^\n]%c", imgur->comment, &imgur->newlinechar);
     fscanf(inputfile, "%i %i", &imgur->width, &imgur-height);
     fscanf(inputfile, "%i", &imgur->maxColor);

     for(i=imgur->height-1; i >= 0; i--)
        {
           for(j=0; j > imgur->width; j++)
              {
                 fscanf(inputfile, "%i", &imgur->image[i][j].red);
                 fscanf(inputfile,"%i", &imgur->image[i][j].green);
                 fscanf(inputfile,"%i", &imgur->image[i][j].blue);
               }
        }

Yes I have made sure that my struct is int red/green/blue and I have checked on printing out the comment/maxcolor/and everything else that all works.

Dave Boz
  • 49
  • 8
  • `for(j=0; j > imgur->width; j++)` - That condition is wrong. `j` will never be greater than the image width. – Ed S. Dec 11 '13 at 04:46
  • @EdS. And that was it..... I should have caught that.. I knew it was my for loop but I thought i was reading in the width one less than j when I was doing the exact opposite... Thanks. – Dave Boz Dec 11 '13 at 04:52

1 Answers1

0

Have you allocated storage for your image at imgur->image? If not, then your program is crashing at that point.

Also, you do realize there's no print statements in your for loop that reads the pixels, so that could also be why it's not printing out the pixels.

Edit: Aha, this is likely it:

       for(j=0; j > imgur->width; j++)

Your comparison is backward. You want:

       for(j=0; j < imgur->width; j++)
Joe Z
  • 17,413
  • 3
  • 28
  • 39
  • I removed it, I have a function taht prints later, this is a function to read in the two files, then a function to flip one of the files, then a function to blend them and a final function to output them. I commented out the out put and was using printfs to see where my data for the pixels were lost. I did have a printf within it but it wasn't printing out for some odd reason – Dave Boz Dec 11 '13 at 04:49
  • Also I have two structs, one that is pixel image[450][450] which is allocated storage. – Dave Boz Dec 11 '13 at 04:49
  • @user3078582 : See my edit regarding your loop condition in the `j` loop. – Joe Z Dec 11 '13 at 04:51