Thread: Parse PPM header with function

  1. #1
    Registered User
    Join Date
    Dec 2018
    Posts
    1

    Parse PPM header with function

    So I have a function that is used to copy over the header of a ppm file to another file and removes the comments. Is there a way to add onto this function so that I can pull out the width and height dimensions? The magic number is always P6 and the max color value is always 255.
    Code:
    void headerinfo(FILE * infile, FILE * outfile, int *wid, int *hei)
    {
    
      char line[100];
      int c;
    
      fgets(line, 100, infile);
      c = strlen(line);
      while (!
             (4 <= c && line[c - 4] == '2' && line[c - 3] == '5'
              && line[c - 2] == '5' && line[c - 1] == '\n')) {
        if (line[0] == '#') {
          fgets(line, 100, infile);
          c = strlen(line);
        } else {
          fputs(line, outfile);
          fgets(line, 100, infile);
          c = strlen(line);
        }
      }
      fputs(line, outfile);
    }
    Last edited by Salem; 12-07-2018 at 02:12 AM. Reason: Removed crayola; Use "copy as text" in your IDE and/or "paste as text" in your browser.

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Why don't you read a bit on what the PPM format is?
    Devoted my life to programming...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 10-19-2011, 07:10 PM
  2. Regex to parse function names?
    By homer_3 in forum C++ Programming
    Replies: 2
    Last Post: 03-30-2011, 02:40 PM
  3. Parse function not reading through entire vector
    By jmd15 in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2007, 04:30 PM
  4. trying to use strtok() function to parse CL
    By ohaqqi in forum C Programming
    Replies: 15
    Last Post: 07-01-2007, 09:38 PM
  5. Replies: 30
    Last Post: 06-19-2006, 12:35 AM

Tags for this Thread