GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 15-Mar-2004, 07:01
spudtheimpaler spudtheimpaler is offline
Junior Member
 
Join Date: Feb 2004
Posts: 46
spudtheimpaler is on a distinguished road

Back to the drawing board...


Hi again. Can you believe the scale and number of projects i have?

This one so far is ok - I think i should be able to get most of it done myself, basically its to create a grid, and then "draw" with asterix's on it.

Thing is i thought i'd take the oppurtunity to play with header files.

Now i'm getting an error :

error C2143: syntax error : missing '{' before 'PCH creation point'

(using visual C++) and i don't think it is the header file, cause i'f i comment out the header file i still have the error, but it wasn't there until i added the header file.

Any ideas? whats the PCH? its before even any functions have gone through so i dont know why its missing a {...

Many thanks

Mitch

CPP / C++ / C Code:

/* * * * * * * * * * * * * * * * * * * * * * * 
 * The Height of all evil - even more C      *
 *                                           *
 * A program to simulate a simple            *
 * drawing package                           *
 *                                           * 
 * EE1E2                                     *
 *                                           *
 * Mitchell Kent + Paul Griffiths.           *
 *                                           *
 * Hopefully the last project of the year    *
 *                                           *
 * Please, please let it be the last of the  *
 * year...                                   *
 *                                           *
 * * * * * * * * * * * * * * * * * * * * * * */

#include <stdio.h>
#include <stdlib.h>

#include "drawing.h"




/*
typedef struct
{
	int X_POS, Y_POS;
	char status, undo_status;
}position;

*/

position ** create_grid(position** grid)
{


	/*This is where the drawing space will be drawn*/
	
	
	int x_size=0, y_size=0;

	int X_POS, Y_POS;

	//position** grid;

	


	printf("Please enter the dimensions (X, Y) of your desired grid\n");
	scanf("%d %d",&GRID_SIZE_X, &GRID_SIZE_Y);


	//allocate memory for rows
    
	grid=(position**)(malloc((x_size)*sizeof(position*)));
    
	//allocate memory for each row of the matrix
    
	for(X_POS=0;X_POS<=(x_size);X_POS++)
		grid[X_POS]=(position*)(malloc((y_size)*sizeof(position)));



	for(Y_POS=0; Y_POS<y_size; Y_POS++)
	{
		for(X_POS=0; X_POS<x_size; X_POS++)
		{
			grid[X_POS][Y_POS].status='.';
			grid[X_POS][Y_POS].X_POS=X_POS;
			grid[X_POS][Y_POS].Y_POS=Y_POS;
			grid[X_POS][Y_POS].undo_status='.';
		}
	}


	for(Y_POS=0; Y_POS<y_size; Y_POS++)
	{
		printf("\n");

		for(X_POS=0; X_POS<x_size; X_POS++)
		{
			printf("%c ", grid[X_POS][Y_POS].status);
		}
	}

	printf("end of function\n");

	return grid;


}



void draw_line()
{

	/*this is where the ability to draw horizontal
	  vertical or diagonal lines will be added    */

}

void fill_space()
{

	/*check for enclosed space and the fill it*/

}

position** negative_image(position** grid)
{

	/*invert image, change * to . and vice versa */

	int x,y;

	printf("error pos 0");

		
	for(y=0; y<GRID_SIZE_Y; y++)
		for(x=0; x<GRID_SIZE_X; x++)
			grid[x][y].undo_status=grid[x][y].status;

			printf("error pos 1");



	for(y=0; y<GRID_SIZE_Y; y++)
		for(x=0; GRID_SIZE_X; x++)
		{
			if(grid[x][y].status=='*')
				grid[x][y].status='.';

			if(grid[x][y].status=='.')
				grid[x][y].status='*';
		}


			printf("error pos 2");


//		print_grid(grid);

		return grid;

}

void undo()
{

	/*revert the changes made in the last go*/

}




void create_circle()
{
	/* create a circle of radius r*/


}

void create_rectangle()
{

	/*create a rectangle*/


}

/*void print_grid(position** grid)
{

	int x, y;


	
	for(y=0; y<GRID_SIZE_Y; y++)
	{
		printf("\n");

		for(x=0; x<GRID_SIZE_X; x++)
		{
			printf("%c ", grid[x][y].status);
		}
	}

}


*/

int main(void)
{

	position** grid;
	
	grid=create_grid(grid);

	printf("%c",grid[1][1].status); //test return of grid


	grid=negative_image(grid);




	printf("\n\n\nsuccess\n");

	return 0;
}


Code:
/* * * * * * * * * * * * * * * * * * * Header File for Lab 5 * * * * * * * * * * * * * * * * * * */ int GRID_SIZE_X; //These variables are required in all functions and it is much easier int GRID_SIZE_Y; //as they are often called but rarely set to consider them as globals typedef struct { int X_POS, Y_POS; char status, undo_status; }position; position ** create_grid(position** grid)
__________________
War doesn't say who's right, only who's left...
  #2  
Old 15-Mar-2004, 07:28
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
CPP / C++ / C Code:
position ** create_grid(position** grid)

Spud. I think the error may be in your header file. The line I showed needs a semicolon so that C knows that it is a function decleration and not the start of the function itself.
  #3  
Old 15-Mar-2004, 07:33
spudtheimpaler spudtheimpaler is offline
Junior Member
 
Join Date: Feb 2004
Posts: 46
spudtheimpaler is on a distinguished road
Quote:
Originally Posted by dsmith
CPP / C++ / C Code:
position ** create_grid(position** grid)

Spud. I think the error may be in your header file. The line I showed needs a semicolon so that C knows that it is a function decleration and not the start of the function itself.

Cheers, that solved my error, though on runing it is crashing now.

Anyway, thanks for looking, brilliant!

Cheers

M
__________________
War doesn't say who's right, only who's left...
  #4  
Old 15-Mar-2004, 08:08
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,720
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by spudtheimpaler
Cheers, that solved my error, though on runing it is crashing now.

Anyway, thanks for looking, brilliant!

Cheers

M

Look at the following (in create_grid()):
Code:
grid=(position**)(malloc((x_size)*sizeof(position*)));

What is the value of x_size? Did you mean to set it to GRID_SIZE_X?
(Also look at y_xsize in its malloc() statement.)

I think it should get through create_grid() with these couple of fixes.


Regards,

Dave
  #5  
Old 15-Mar-2004, 08:14
spudtheimpaler spudtheimpaler is offline
Junior Member
 
Join Date: Feb 2004
Posts: 46
spudtheimpaler is on a distinguished road
Quote:
Originally Posted by davekw7x
Look at the following (in create_grid()):
Code:
grid=(position**)(malloc((x_size)*sizeof(position*)));

What is the value of x_size? Did you mean to set it to GRID_SIZE_X?
(Also look at y_xsize in its malloc() statement.)

I think it should get through create_grid() with these couple of fixes.


Regards,

Dave

Thats just me changing variables and not checking through them to make sure they're the same

Thanks Dave, kinda pissed at myself for not seeing it.

Cheers again
Mitch
__________________
War doesn't say who's right, only who's left...
  #6  
Old 15-Mar-2004, 08:36
spudtheimpaler spudtheimpaler is offline
Junior Member
 
Join Date: Feb 2004
Posts: 46
spudtheimpaler is on a distinguished road
CPP / C++ / C Code:

position** print_grid(position** grid)
{

	int x, y;

	printf("get to print grid function");
	
	for(y=0; y<GRID_SIZE_Y; y++)
	{
		printf("\n");

		for(x=0; x<GRID_SIZE_X; x++)
			printf("%c ", grid[x][y].status);
	}

	return grid;

}


why is this erroring? I'm getting

c:\programming\ee1e2\drawing\main.c(143) : warning C4013: 'print_grid' undefined; assuming extern returning int
c:\programming\ee1e2\drawing\main.c(143) : warning C4047: '=' : 'struct position ** ' differs in levels of indirection from 'int '
c:\programming\ee1e2\drawing\main.c(177) : error C2040: 'print_grid' : 'struct position **(struct position ** ) ' differs in levels of indirection from 'int ()'
c:\programming\ee1e2\drawing\main.c(206) : warning C4047: '=' : 'struct position ** ' differs in levels of indirection from 'int '
Error executing cl.exe.

all of the above due to that function, or specifically a call to that function from

CPP / C++ / C Code:

position** negative_image(position** grid)
{

	/*invert image, change * to . and vice versa */

	int x,y;

		
	for(y=0; y<GRID_SIZE_Y; y++)
		for(x=0; x<GRID_SIZE_X; x++)
			grid[x][y].undo_status=grid[x][y].status;

			printf("error pos 1");



	for(y=0; y<GRID_SIZE_Y; y++)
		for(x=0; x<GRID_SIZE_X; x++)
		{
			if(grid[x][y].status=='.')
				grid[x][y].status='*';


			if(grid[x][y].status=='*')
				grid[x][y].status='.';
		}


			printf("error pos 2");


		grid=print_grid(grid); //here **********

		return grid;

}



why is it assuming its returning an int when i say it should return the pointer?

if i remove ( or comment out ) the line marked above, the program runs fine. I realise I'm calling a function from within a function, but I'm only passing through a pointer that is already called in the initial function and returning it. I've tried passing the grid pointer and not returning anything (cause i dont really need to) but that was still causing the same error (hence me trying with returning the pointer)

I think i had v similar trouble with the mars rover project (which i still need to do, orgh) but i still don't understand where the problem lies.

If anyone could have a quick glance at it.

Many thanks.
Mitch
__________________
War doesn't say who's right, only who's left...
  #7  
Old 15-Mar-2004, 08:47
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,720
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by spudtheimpaler
[c]


why is this erroring? I'm getting

c:\programming\ee1e2\drawing\main.c(143) : warning C4013: 'print_grid' undefined; assuming extern returning int

all of the above due to that function, or specifically a call to that function from


If anyone could have a quick glance at it.

Many thanks.
Mitch

In your original post, print_grid(), and the call to it, was commented out.

Now, if you haven't changed its position in your source file, print_grid() is defined after negative_image() invokes it. The warning that I have included above tells you something: Whenever C encounters a function that it does not know anything about, it assumes it returns int, and it assumes that all arguments are int. Put a prototype declaration of print_grid() somewhere in the file before the function's first invocation:

Code:
void print_grid(position** grid);

Then look at other compiler messages, work through them one at a time.

Cheers!

Dave
  #8  
Old 15-Mar-2004, 08:53
spudtheimpaler spudtheimpaler is offline
Junior Member
 
Join Date: Feb 2004
Posts: 46
spudtheimpaler is on a distinguished road
Quote:
Originally Posted by davekw7x
In your original post, print_grid(), and the call to it, was commented out.

Now, if you haven't changed its position in your source file, print_grid() is defined after negative_image() invokes it. The warning that I have included above tells you something: Whenever C encounters a function that it does not know anything about, it assumes it returns int, and it assumes that all arguments are int. Put a prototype declaration of print_grid() somewhere in the file before the function's first invocation:

Code:
void print_grid(position** grid);

Then look at other compiler messages, work through them one at a time.

Cheers!

Dave

I've included a function declaration in the header - sorted out the problem.

I don't know why i didn't see it, sorry to bug you with the little things i should have noticed myself.

Cheers, again.
Mitch
__________________
War doesn't say who's right, only who's left...
  #9  
Old 15-Mar-2004, 09:03
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,720
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by spudtheimpaler
I've included a function declaration in the header - sorted out the problem.

I don't know why i didn't see it, sorry to bug you with the little things i should have noticed myself.

Cheers, again.
Mitch

A few times through the crash/burn loop, and you will find easier spot the significant compiler messages (sometimes known as picking the fly specks out of the pepper). I personally like to eliminate all warnings (within reason), or, at least make sure I understand what it is that I am ignoring.

[edit]
Does you mean that you found your bug(s) in neg_image() and print_grid()?
[/edit]

Dave

"I was born not knowing, and have only had a little time to change that, here and there."

--- Richard P. Feynman
Last edited by davekw7x : 15-Mar-2004 at 10:09.
  #10  
Old 15-Mar-2004, 10:12
spudtheimpaler spudtheimpaler is offline
Junior Member
 
Join Date: Feb 2004
Posts: 46
spudtheimpaler is on a distinguished road
Quote:
Originally Posted by davekw7x
A few times through the crash/burn loop, and you will find easier spot the significant compiler messages (sometimes known as picking the fly specks out of the pepper). I personally like to eliminate all warnings (within reason), or, at least make sure I understand what it is that I am ignoring.


Dave

"I was born not knowing, and have only had a little time to change that, here and there."

--- Richard P. Feynman

Feynman - Genius.

Indeed, I am learning. And I'm getting better at the debugging process. The only warning i get now i know why its there and that its ok to ignore.

I'll try to quit asking the easy questions - I'm getting there slowly.

Cheers again,
Mitch
__________________
War doesn't say who's right, only who's left...
 
 

Recent GIDBlogDeveloping GUIs with wxPython (Part 3) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Free message board hosting, 30 skins, 11 languages. edkhosting Free Web Hosting 1 27-Feb-2004 13:14
This message board nniehoff Web Design Forum 4 20-Aug-2001 02:22

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 05:31.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.