PDA

View Full Version : Beginning C Program Not Working


toymachine22122
05-26-2004, 12:14 AM
EDIT:
Alright, I think I found the problem: It's trying to make a temp dir using make.exe, which I don't have. So now I've searched around on Yahoo and can't find where I could download a replica. I already have CYGWIN but that didn't come with anything like that. Correct me if this is not the problem, but if it is, could someone tell me where I can get a copy of make.exe?
-------------------------------------------------------------------------------------------------

Well guys, I started out with HTML, then JavaScript, then Perl, then whatever language mIRC scripting is in, and now I think I'm ready to start C.

The problem?

I downloaded some tutorials and stuff and they give me a sample program. I am using DevC++, here is what I do (I'm running Windows XP Home if it makes any difference):
1) Open Dev-C++
2) Click New Project
3) Create as "Console Application" type "C Project"
4) Copy+Paste the program from the tutorial to Dev-C++. Program code is at bottom of my post.
5) Go to Execute->Compile

Then this appears at the bottom of the window:
http://server5.uploadit.org/files/ToyMachine22122-ssw.jpg

Here's the program code:
#ident "@(#) Hello World - my first program"

#include <stdio.h>

char *format = "%s",
*hello = "Hello World...\n";

main()
{
printf ( format, hello );
}

What am I doing wrong and do I need any other programs?

Unit
05-26-2004, 12:37 AM
what is the filename the error is on?

liorean
05-26-2004, 12:52 AM
Hmm, shouldn't that produce an error? I mean, main must in ANSI C be of the type int, and isn't returning a value a requirement for all functions of other types than void?


Also, doesn't CYGWIN port the Linux make utility? Why don't you try using that one?

Spookster
05-26-2004, 01:37 AM
Compiled and ran fine for me using Dev C++.

You are suppose to declare it like:

int main()

however I believe that ANSII doesn't require that it fail if it not declared in that way. So if you have it like:

void main() or just main() it will still compile and probably run.

toymachine22122
05-26-2004, 01:47 AM
Also, doesn't CYGWIN port the Linux make utility? Why don't you try using that one?Yes, it does have a make utility, but it can't compile C scripts.

Compiled and ran fine for me using Dev C++.Probably because you have make.exe somewhere on your system, no?

Sorry I forgot to post the errors earlier, here they are:
Compiler: Default compiler
Building Makefile: "C:\Documents and Settings\Greg\My Documents\Makefile.win"
Executing make...
make.exe -f "C:\Documents and Settings\Greg\My Documents\Makefile.win" all
Execution terminated

Also I found a windows ported NMAKE command, don't really know how to use it though. If it's usable, would someone please tell me how to set it up so that it will use NMAKE.exe instead of MAKE.exe?

Spookster
05-26-2004, 07:41 AM
I did not use the project files. I just compiled it by itself. Have you tried compiling it outside of a project?

whackaxe
05-26-2004, 10:48 AM
Compiler: Default compiler
the default compiler for DEVCPP is Mingw. are you shure youve got it set up correctly for CYGWIN?

toymachine22122
05-27-2004, 12:39 AM
I did not use the project files. I just compiled it by itself. Have you tried compiling it outside of a project?
That's the only way I did it.

the default compiler for DEVCPP is Mingw. are you shure youve got it set up correctly for CYGWIN?
Slow down, I'm pretty stupid about this stuff so it's hard for me to decode. I'm not using CYGWIN for anything right now (unless Dev-C++ for whatever reason uses it by default) and I'd like to avoid using it if at all possible because the more I use it the more I tend to hate it. To tell the truth I don't think I've changed any of Dev-C++'s default settings (maybe this is a problem?).

But if using it is a must, then how would I set MINGW up for CYGWIN?
And if I did, wouldn't it still try to use make.exe somewhere in there?

Sorry I'm so slow here guys. :confused:

Spookster
05-27-2004, 06:12 AM
That's the only way I did it.


Slow down, I'm pretty stupid about this stuff so it's hard for me to decode. I'm not using CYGWIN for anything right now (unless Dev-C++ for whatever reason uses it by default) and I'd like to avoid using it if at all possible because the more I use it the more I tend to hate it. To tell the truth I don't think I've changed any of Dev-C++'s default settings (maybe this is a problem?).

But if using it is a must, then how would I set MINGW up for CYGWIN?
And if I did, wouldn't it still try to use make.exe somewhere in there?

Sorry I'm so slow here guys. :confused:

You don't need CYGWIN to use Dev C++. I tested what the code you posted previously using a WinNT box with Dev C++ which happens to have CYGWIN installed and that worked just fine. Now I just did a fresh install of DevC++ on my WinXP machine which does not have CYGWIN installed. Your code worked just fine there too.

Try unistalling Dev C++ and make sure you have the latest release of DevC++ and do a fresh install and just accept the default settings.

Unit
05-27-2004, 06:44 AM
I can confirm that default installation works fine without any changes on XP. I just tested it :)

boris
05-27-2004, 02:00 PM
that must be a crappy tutorial
for one it uses global variable (try to stay away from these) and two the format of input/output statements should stay inside the function call
here this is what it should be using proper coding standards

#include <stdio.h>

int main()
{
printf("Hello World...\n");
return 0;
}

toymachine22122
05-27-2004, 07:31 PM
that must be a crappy tutorial
for one it uses global variable (try to stay away from these) and two the format of input/output statements should stay inside the function call
here this is what it should be using proper coding standards

#include <stdio.h>

int main()
{
printf("Hello World...\n");
return 0;
}


Actually it said something about a reason why it used a global variable (for later demonstration programs i think), although I don't know what those are yet, and it also said that you should not use a global variable if this was going to be your entire program.

Also it's a pretty credible source that made the tutorial and a few people have recommended it to me, it was made by a fellow named Chris Sawell I believe, and considering the tutorial's length I doubt it was just thrown together. Why waste all that time typing if your programs are lazy and poorly coded?

But let's not get off-topic here; more effecient code is not going to solve my problem.

Just a little thing I figured I'd add while I'm at it here, it's obviously not a problem with the code or anything because none of the sample programs with Dev-C++ work either.

I'm using Dev-C++ 5.0 beta 8 (4.9.8.0) (12 MB) with Mingw/GCC 3.2

boris
05-28-2004, 04:17 AM
yeah true, i tell you what, i learnt a lot of C in the last 6 months at uni. you really should get a textbook and learn that way cos that gets you well and truly started