News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

New to C and CODEBLOCKS

Started by bioya1, April 22, 2020, 04:12:21 AM

Previous topic - Next topic

bioya1

Newbie, so please be patient.
Learning C (not C++) on my own, and using CODEBLOCKS.
I create a project and then add 2 pgms (Pgm1.c, Pgm2.c) to it. Both pgms are very simple.
In Code Blocks, under the project &  source I see both pgms.
I highlight Pgm1 executes great, but I cannot execute Pgm2, even though its highlighted and it's the one I want. Pgm1 always executes.
What am I doing wrong? Thanks!

BlueHazzard

You have to use one program (one main function) per project...

It is possible to have multiple main functions per project, but this is advanced usage and for beginning it is more convenient to have one project per main function.... You can open multiple project in codeblocks at the same time...

bioya1

Hello Blue,

I'm used to Java where a project can have many "MAIN" classes.
Thank you for the response.

bioya1

May I ask one question?
Does this mean that every pgm I write will require its own project?
Maybe I can write 1 MAIN pgm which can call the others?  What do you think?

oBFusCATed

You can do whatever you like :)
What is best depends on the circumstances.
How much time do you spend per program?
What is the fraction of the time required to create the project relative to the actual process of programming?
Do you want to debug?

Generally C::B supports using the default compiler to compile single files without the need for a project, but you cannot debug those...
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

bioya1

In the beginning stages (in which I am) the pgms will short. So if I don't have to have connected pgms I would prefer to not stick projects in there unless I must. Can this be done in Code Blocks? It's not apparent that I can, but as a newbie it all looks strange. Thank you.

oBFusCATed

1. Open a file which is self sufficient (doesn't require libs or other .c/cpp files)
2. Build -> Build and run or F9
3. Have fun...
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

bioya1

Will try. Many thanks for pointing me in this direction.

:)