Thread: Parse Error that has me stumped

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    12

    Parse Error that has me stumped

    I have written the following, and when I compile I get one recurring parse error that I cannot figure out what I have done. Would someone please take a look at it and see is they can find what I'm missing??? Here's the code. I am trying to create a simple grey box. {BTW: The UNIX system we use does not have a rasterfile.h, so we had to create the structure.}

    Thanks in advance!

    Sandy

    Code:
    #include<stdio.h>
    
     struct rasterfile{
        int ras_magic;
        int ras_width;
        int ras_height;
        int ras_depth;
        int ras_length;
        int ras_type;
        int ras_maptype;
        int ras_maplength;
      };
    
    int imagesave(unsigned char);
    main()
    {
    
      unsigned char img[500][500];
      int i=0,j=0;
    
    
      for(i=0; i<=500; i++)    
          for(j=0; j<=500; j++)	
    		  img[i][j] = 128;
    
    imagesave(unsigned char img); /*here's where the parse error is - - -
              parse error before unsigned*/
    
    }
    
    int imagesave(unsigned char img)  
    {
    
      int fi;
      int colormap[3][256];
    
      struct rasterfile header;
    
        fi = creat("testfile.ras", 0644);
        header.ras_magic=0x59a66a95;
        header.ras_width=500;
        header.ras_height=500;
        header.ras_depth=8;
        header.ras_length=1;
        header.ras_type=0;
        header.ras_maptype=0;
        header.ras_maplength=768;
    
        write(fi, &header, sizeof(struct rasterfile));
        write(fi, colormap, 256*3);
        write(fi, img, header.ras_height*header.ras_width);
    
        close(fi);
      
    return (img);
    }
    Thanks Again!

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    you are declaring the arrays 500 wide

    0 to =500 is 501 (not to mention the null terminator character that the compiler may insert)

    unsigned char img[500][500];
    for(i=0; i<=500; i++)

    should be
    for(i=0; i<500; i++)

    try using a const say
    #define IMAGE_WIDTH 500
    #define IMAGE_HEIGHT 500

    EDIT:

    I would pass the image as a pointer to the char array rather than the instance you are passing (it may actually generate an error). Also I would use a single dimension array

    char Image[IMAGE_WIDTH*IMAGE_HEIGHT];//easier if you are going to try and save it or use SetDIBits() ect.

    and I would dynamicly alloc it.
    Last edited by novacain; 05-28-2002 at 03:04 AM.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > imagesave(unsigned char img); /*here's where
    Because this is a function prototype, not a function call

    To make literal sense with your real prototype, it would be
    imagesave( img[0][0] );

    But that doesn't really make any sense, if you were hoping to read stuff inside the array, by calling imagesave

    So you would need this
    /* prototype */
    int imagesave(unsigned char img[][500] );

    /* Call */
    imagesave( img );

    Other comments by novacain about array bounds as well

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    12
    Thanks Salem and Novacain! I got it working with the help of both of you!

    I also took your advice novacain and declared the rows and columns as constant.

    Thanks again!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  2. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  3. string ?
    By cogeek in forum C Programming
    Replies: 27
    Last Post: 12-05-2004, 10:45 PM
  4. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM