Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can someone please show me what is wrong with this code?? Please Help! 1

Status
Not open for further replies.

DonCL

Programmer
Jul 16, 2001
43
US
Hi, what im trying to do is get this description to work (which i have on another thread):

A Computer graphics image is composed of rectangular points on the screen. In a black and white picture, we can use 0 to represent white and 1 for black. The picture is a 5 x 5 square on the screen as follows:
1 1 0 1 0 1 1 0 0 0
1 0 0 1 1 1 0 0 0 0
1 0 1 1 1 1 0 0 0 0
0 1 [/b]1 0 1 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
(initial image) (image after exe of ErasePic function)

Two black pixels are part of the same object if we can get from one to the other with horizontal and vertical moves. Thus, Fig 1(initial image) contains 2 objects.
Write a function ErasePic to erase the object of which the given black pixel is part. Invoking the function for the bold face 1 results in erasing a representation of the rightmost object of Fig 1 (see Fig 2).


Someone recommended this, which i tried to execute and its not working. here is the code and the errors I get:
Code:
void FindBlock(int *aBmp, int nSize, int cx, int cy){

	if (aBmp[cx][cy] == 0) || aBmp[cx][cy] > 1; return
	if (aBmp[cx][cy] == 1) || aBmp[cx][cy] +1000;
	if (cx > 0) FindBlock(aBmp, nSize, cx-1, cy);
	if (cx < nSize -1) FindBlock(aBmp, nSize, cx+1, cy);
	if (cy > 0) FindBlcok(aBmp, nSize, cy, cy-1);
	if (cy < nSize-1) FindBlock(aBmp, nSize, cx, cy+1);
}

ClearBlock(int *aBmp, int nSize) {
	for (int m=0; m < nSize; m++)
		for (int n=0; n < nSize; n++)
			if (aBmp[m][n] > 1) aBmp[m][n] = 0;
}

ErasePic(int *aBmp, int nSize, int cx, int cy) {
	FindBlock(aBmp, nSize, cx, xy);
	ClearBlock();
}
Errors
subscript requires array or pointer type
missing ';' before '||'
syntax error : 'if'
'FindBlcok' : undeclared identifier
subscript requires array or pointer type
subscript requires array or pointer type
'=' : left operand must be l-value
warning C4508: 'ClearBlock' : function should return a value; 'void' return type assumed
'xy' : undeclared identifier
'ClearBlock' : function does not take 0 parameters
warning: 'ErasePic' : function should return a value; 'void' return type assumed

If someone can show me what is wrong with this, ive been at this for hrs, i would really appreciate it. Thanks alot!!
GOD BLESS AMERICA
 
Sorry, only the one is supposed to be bold before the first zero that is bold. it should look like this:
1 1 0 1 0 1 1 0 0 0
1 0 0 1 1 1 0 0 0 0
1 0 1 1 1 1 0 0 0 0
0 1 1 0 1 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0

sorry for the confusion
 
The following version compiles as C++, at least

void FindBlock(int aBmp[][5], int nSize, int cx, int cy)
{

if ((aBmp[cx][cy] == 0) || aBmp[cx][cy] > 1) return;
if (aBmp[cx][cy] == 1) aBmp[cx][cy] = 2;
if (cx>0) FindBlock(aBmp, nSize, cx-1, cy);
if (cx<nSize-1) FindBlock(aBmp, nSize, cx+1, cy);
if (cy>0) FindBlock(aBmp, nSize, cy, cy-1);
if (cy<nSize-1) FindBlock(aBmp, nSize, cx, cy+1);
}

void ClearBlock(int aBmp[][5], int nSize)
{
for (int m=0; m < nSize; m++)
for (int n=0; n < nSize; n++)
if (aBmp[m][n] > 1) aBmp[m][n] = 0;
}

void ErasePic(int aBmp[][5], int nSize, int cx, int cy) {
FindBlock(aBmp, nSize, cx, cy);
ClearBlock(aBmp, nSize);
} :) I just can't help it, I like MS...:)
 
Thanks a lot, DavesTips, i will give it a shot. i will let u know how it turns out!
 
ok, it compiles like u said, but i get 2 errors when i build it, so it will not execute. here are the errors:
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
c:\2.exe : fatal error LNK1120: 1 unresolved externals


Do you know what it could be? i cant figure it out. i would really appreciat any help.

GOD BLESS AMERICA
 
well, i know i have to put a main in there, but what would go under it? anybody have any suggestions? please help...
 
Hi Don,

Sorry to keep you waiting, the time's a bit different here in Germany :)

Yes, any standard C(++) program (such as a VC++ Win32 Console App, which I guess is what you're using) needs a main() routine, which is exported by the compiler as &quot;_main&quot;. This is where the runtime code starts your program. Also, somewhere you have to set up your parameters to ErasePic() and call that routine. (Hmm., EraseBlock() might be a better name...)

You can add the following code to your routine, and everything should work:

void printBlock(int aBmp[][5], int nSize)
{
for (int m=0; m < nSize; m++)
{
for (int n=0; n < nSize; n++)
cout << setw(3) << aBmp[m][n];
cout << endl;
}
cout << &quot;***************&quot; << endl;
}

int main(int argc, char* argv[])
{
int block[5][5] = {{1,0,0,1,0},
{1,0,1,1,0},
{1,0,1,0,0},
{1,0,1,1,0},
{1,0,0,0,0}};
printBlock(block,5);
ErasePic(block,5,2,2);
printBlock(block,5);

return 0;
}

I also added printBlock() to output the array to the console window. To compile this, you also need to add these lines to your .cpp file, after the #include &quot;stdafx.h&quot;:

#include <iostream>
#include <iomanip>
using namespace std;

Also, either step through the code with F10, or put something like

char c;
cin >> c;

just before return in main(), otherwise the program will run and disappear before you can see the results.
:) I just can't help it, I like MS...:)
 
Thanks again dave, Im sorta new at this, i really appreciate your help!!:)
 
Hey Dave, do u live in Germany or work there? that must be nice...
 
I live and work here, but I guess it's much like living and working anywhere else...:) :) I just can't help it, I like MS...:)
 
thats true, but europe is so nice. Dont get me wrong, I love New York, but its nice to see how easy it is for people all over the world communicate :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top