User forums > Using Code::Blocks
Tutorial for person new to IDEs
LowWaterMark:
Thanks dmoore. I sincerely appreciate your reply and of course, your time.
One thing however - the main.c file isn't coming up for me as a blank entry point into the project (did I install Code::Blocks incorrectly?). It's the source code for the "Hello World" thing. Is there any way to create a New Project with the Console Wizard without having the main.c file ("Hello World") included by default in the Source File folder? It may be irrelevant, but there must be a way to get rid of it unless I want every project I create in Code::Blocks IDE to say "Hello World" when I execute it.
More importantly, the function for telling the machine where to start reading in the main.c source file reads int main(). Not just main() but int main(). The int part of this main() function line confuses me. Does it have something to do with the source file's name also being main.c? Do I have to get it out of the trials folder in the default path C:\Program Files\CodeBlocks\trials\*. At any rate, I get error messages for "multiple definitions of main()" when I try to write a new source file, I imagine because the main.c "Hello World" source file is within every project I try to create in Code::Blocks.
I can imagine my portfolio in a few years: 200 some-odd projects that start out by saying "Hello World" 8) . . .
Seriously, I know it is me, not the program. Nonetheless, I am stumped. Code::Blocks is famous for being easy. What pray tell could I be doing wrong?
LowWaterMark:
Allow me to distill down my own confusion. The Alpha and the Omega:
main()
{
return 0;
}
meaning: start executing code here and return to DOS here. What's the meaning of inserting int in front of the main() Function?
FWIW, I'm using "Absolute Beginner's Guide to C", Second Edition, by Greg Perry. In 365 pages it never mentions prefixing the main() Function with int. Does this int tell the compiler to be heads up for an integer type of value to be returned from the program when it ends (i.e. the zero in return 0)?
Can anyone id the locus of my confusion? Thx.
dmoore:
--- Quote from: LowWaterMark on August 07, 2008, 10:56:47 am ---Thanks dmoore. I sincerely appreciate your reply and of course, your time.
One thing however - the main.c file isn't coming up for me as a blank entry point into the project (did I install Code::Blocks incorrectly?). It's the source code for the "Hello World" thing. Is there any way to create a New Project with the Console Wizard without having the main.c file ("Hello World") included by default in the Source File folder? It may be irrelevant, but there must be a way to get rid of it unless I want every project I create in Code::Blocks IDE to say "Hello World" when I execute it.
--- End quote ---
The default template is just a helpful stub. It gives you a quick way to test that the compiler/IDE are functioning correctly before you start coding. It is trivial to delete the parts of the file that you don't want or to just remove the file from the project in its entirety (right click in the project manager window -> remove from project)
if you want to change the default project files you have at least a couple of options:
1. you could edit main.c in [Your CB Installation Dir]\share\CodeBlocks\templates\wizard\console\c
2. create your own project wizard based on other wizards (take a look at the contents of [Your CB Installation Dir]\share\CodeBlocks\templates\wizard\). There's probably stuff in the wiki on how to do this
Also keep in mind if you are only writing simple one-file programs, you don't need to create a project at all. Close all open projects and create an empty file. Write your program in that file, save it. Then you will be able to compile and run it from CB
--- Quote ---More importantly, the function for telling the machine where to start reading in the main.c source file reads int main(). Not just main() but int main().
--- End quote ---
In ANSI C (i.e. standard C) main always returns an int. That int is the error code returned to the calling process (i.e. the program that called your program). The convention is to return zero if the program terminates normally.
--- Quote ---At any rate, I get error messages for "multiple definitions of main()" when I try to write a new source file, I imagine because the
--- End quote ---
as I said, you can have at most one main in each build target (this is the way the C programming language works and isn't a CB restriction). thus, if you want to put main in a different file from main.c then you either have to remove main.c or at least delete the main function from main.c
it seems that many of your questions are programming questions as opposed to CB questions. your needs might be better met on a dedicated programming board/forum (e.g. comp.lang.c (through google groups) codeguru or gamedev). we can only give you very limited programming help on this board because the topics must be CB related.
LowWaterMark:
Sorry for posting in the wrong arena. Ironically your response helped me out quite a lot with the big picture architecture behind code::blocks. I'm departing these wilds and looking into the forums you suggested. Thanks for the links and thanks for your time.
Navigation
[0] Message Index
[*] Previous page
Go to full version