C does not go to the next line while reading .ppm -


so have .ppm file , goal read each pixel corresponding r[] g[] , b[] elements. code reads first line (idk correct or not), not go further. i'm unsure if need these getc(fp); in order skip spaces. reading each line , parsing int not option. help.

int main(int argc, char** argv)      {         int height;         int width;         int max;         file *fp;         fp = fopen("vit_small.ppm", "r");         fscanf(fp, "%*[^\n]\n", null);         fscanf(fp, "%d %d", &width, &height);         printf("width %d height %d \n", width, height);         fscanf(fp, "%d", &max);         printf("maximum value %d \n", max);         int r [height][width];         int g [height][width];         int b [height][width];         int hist [5];         int w = 0;         int h = 0;         char buffer [1000];         (;w<height;w++)         {             printf("row number %d \n", w);             (;h<width;h++)                 {                 fread(&r[w][h], 1, 1, fp);                 printf("%d ", r[w][h]);                 getc(fp);                 fread(&g[w][h], 1, 1, fp);                 printf("%d ", g[w][h]);                 getc(fp);                 fread(&b[w][h], 1, 1, fp);                 printf("%d ", b[w][h]);                 getc(fp);                 }             getc(fp);             printf("\n");         }          int = 0;         int j = 0;         (;i<height; i++)          {             (;j<width; j++)              {                 printf("%d %d %d ", r[i][j], g[i][j], b[i][j]);             }         printf("\n");         }       fclose(fp);      file * res;      res = fopen ("image_output.ppm", "w");      fprintf (res, "p6\n");      fprintf(res, "%d\n", width);      fprintf(res, "%d\n", height);      fprintf(res, "%d\n", max);      = 0;      j = 0;      for(; < height; i++)      {          for(; j < width; j++)          {              fprintf(res, "%d %d %d", r[i][j], g[i][j], b[i][j]);          }          fprintf(res,"\n");      }         return (exit_success);     } 

the p6 format of ppm stores each primary byte , there no rows , no spaces. if image 10 6, have 180 bytes (10x6x3) following 255 , newline character. see wikipedia entry on ppm.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -