function compile error

This is a discussion on function compile error within the C Programming forums, part of the General Programming Boards category; cant see why this wont compile Code: #include <stdio.h> #include <ep100lib.h> int Image_Invert(int image_data[height][width], int height, int width) { int ...

  1. #1
    kiz
    kiz is offline
    Registered User
    Join Date
    Sep 2007
    Posts
    25

    function compile error

    cant see why this wont compile

    Code:
    #include <stdio.h>
    #include <ep100lib.h>
    
    int Image_Invert(int image_data[height][width], int height, int width)
    {
    int row, column, red, green, blue;
    
    for(row=0;row <= height; row++)
    	{
    	for(column=0; column<= width; column++);
    		{
    		red = 255-((image_data[row][column]>>16)&0xff);
    		green = 255-((image_data[row][column]>>8)&0xff);
    		blue = 255-((image_data[row][column])&0xff);
    		image_data[row][column] = ((red<<16)&(green<<8)&(blue));
    		}
    	}
    return image_data;
    }
    
    int main(int argc, char **argv)
    {
    char               *file = NULL;
    int                 no = 1;
    int height;
    int width;
    int image_data[EP100_LIB_MAX_X][EP100_LIB_MAX_Y];
    
    	if (argc < 2)		// if there are not enough arguments.
    		return 1;
    
    	// now your code to get and process the CLA.....
    
    	file = argv[no];
    
    	ep100_lib_init();		// Initialise the ep100 library of routines.		return 1;
    
    	// now your code to get and process the CLA.....
    
    	file = argv[no];
    
    	ep100_lib_init();		// Initialise the ep100 library of routines.
    
    	ep100_lib_open_image(file);
    
    	height=ep100_lib_get_image_height();
    	width=ep100_lib_get_image_width();
    	fprintf(stdout,"Image is %dx%d\n",width,height);
    
    	
    	ep100_lib_get_data(image_data);
    	ep100_lib_print_data(image_data);
    	
    	image_data[height][width] = Image_Invert(image_data[height][width], height, width);
    
    //	image_process_invert_data(image_data);
    	
    //	ep100_lib_set_data(image_process_emboss_data(image_data));
    
    	ep100_lib_set_data(image_data);
    
    	sleep(5);		// This gives us a chance to see the orginal and then the new one appears
    	ep100_lib_display_image();	// Click in the window to exit the program, button 3 zooms
    
    	ep100_lib_close();
    
       return 0;
    }
    the errors are because of the Image_Invert function

    these are the errors

    Code:
    cc -I. -I/usr/units/ep100/ass2.072/ `imlib2-config --cflags` -g   -c -o Image.o Image.c
    Image.c:4: error: ‚height‚ undeclared here (not in a function)
    Image.c:4: error: ‚width‚ undeclared here (not in a function)
    Image.c: In function ‚main‚:
    Image.c:54: error: type of formal parameter 1 is incomplete
    make: *** [Image.o] Error 1
    does anyone know how i can fix it??

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,532
    > int Image_Invert(int image_data[height][width], int height, int width)
    This needs to be
    int Image_Invert(int image_data[EP100_LIB_MAX_X][EP100_LIB_MAX_Y], int height, int width)

    > return image_data;
    You can't return a whole array, and this just returns the passed in pointer.
    But since your return type is int, this is the wrong type anyway.
    Since the array was passed as a pointer, all the changes have been made to the original anyway.

    And the call needs to be
    Image_Invert(image_data, height, width);

    > for(column=0; column<= width; column++);
    1. Watch the ; at the end
    2. Do you really mean <= here, given that you start at 0
    Look up "fence-post" errors on the web.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    This bit is duplicated:
    Code:
    	// now your code to get and process the CLA.....
    
    	file = argv[no];
    
    	ep100_lib_init();		// Initialise the ep100 library of routines.		return 1;
    Code:
    	sleep(5);		// This gives us a chance to see the orginal and then the new one appears
    Use something that waits for the user to press enter or such - not a static 5 second time, it may get annoyingly long if you are not interested in seeing the original image, and it's almost certainly too short if you really want to study the original.

    Code:
    		image_data[row][column] = ((red<<16)&(green<<8)&(blue));
    Will almost certainly be zero always.


    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 12:17 AM
  2. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 02:49 PM
  3. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 09:43 AM
  4. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM
  5. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 04:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21