Sign in to follow this  
1stMan

Running a program

Recommended Posts

I'm a real beginner and I'm sorry for the level of question this is, but I have a problem running some code. I copied the code from a website that said this: "...we have included a small program written in "C". If you have a C compiler, try it out. It is a complete working program." I've tried running the code and just can't get it to work? Can somebody please help? I've put the code below. Thanks. #include "stdio.h" #define MaxIters 200 #define SIZE 80 #define BLACK -1 #define LEFT -2.0 #define RIGHT 1.0 #define TOP 1.0 #define BOTTOM -1.0 main(int argc, char *argv[]) { short x, y, count; long double zr, zi, cr, ci; long double rsquared, isquared; for (y = 0; y < SIZE; y++) { for (x = 0; x < SIZE; x++) { zr = 0.0; zi = 0.0; cr = LEFT + x * (RIGHT - LEFT) / SIZE; ci = TOP + y * (BOTTOM - TOP) / SIZE; rsquared = zr * zr; isquared = zi * zi; for (count = 0; rsquared + isquared <= 4.0 && count < MaxIters; count++) { zi = zr * zi * 2; zi += ci; zr = rsquared - isquared; zr += cr; rsquared = zr * zr; isquared = zi * zi; } if (rsquared + isquared <= 4.0) printf("*"); else printf(" "); } printf("\n"); } return 0; }

Share this post


Link to post
Share on other sites
I'm running it in Visual Studio.

The errors are:

LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16

&

Debug/fractal2.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

Share this post


Link to post
Share on other sites
Looks like you're trying to compile a Win32 app, when what you've written is a console application.

The compiler is looking for an entry into a WinMain function that doesn't exist.
Try starting a "new" project and specifying that it will be of a Win32 console type (not Win32) to avoid that linking error.

Share this post


Link to post
Share on other sites
I think you've created a Windows application, when you meant to create a console application. If you're using Visual Studio, try creating a new project, then for the project type, use 'Win32 Console Application'. Then you'll be set. BTW: You may want to have a return type for the main function (see below).

int main(int argc, char *argv[]) {

...

return 0;
}

Hope that helps.

-Otakuidoru

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this