Running a program
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;
}
What compiler are you using? The message almost looks likie it says it wrote it to your C drive and now you need a C compiler to finish it. Knowing the compiler your using would be great. [grin]
I can't really see anything wrong with the syntax. Can you give us the errors your getting? Or does the program just crash?
--Ter'Lenth
--Ter'Lenth
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.
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.
Sounds to me like your trying to compile it as a Win32 application, try copying the following code to a differen't project and make it console based.
Yeah that is what I've done. I had no idea which one to choose so I just guessed. I'll try the console based one.
Thanks a lot for the help.
Thanks a lot for the help.
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.
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.
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
int main(int argc, char *argv[]) {
...
return 0;
}
Hope that helps.
-Otakuidoru
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement