Author Topic: New to C and CODEBLOCKS  (Read 2747 times)

Offline bioya1

  • Single posting newcomer
  • *
  • Posts: 5
New to C and CODEBLOCKS
« on: April 22, 2020, 04:12:21 am »
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!

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: New to C and CODEBLOCKS
« Reply #1 on: April 22, 2020, 08:03:01 am »
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...

Offline bioya1

  • Single posting newcomer
  • *
  • Posts: 5
Re: New to C and CODEBLOCKS
« Reply #2 on: April 22, 2020, 04:22:29 pm »
Hello Blue,

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

Offline bioya1

  • Single posting newcomer
  • *
  • Posts: 5
Re: New to C and CODEBLOCKS
« Reply #3 on: April 22, 2020, 06:32:03 pm »
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?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: New to C and CODEBLOCKS
« Reply #4 on: April 22, 2020, 07:13:44 pm »
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!]

Offline bioya1

  • Single posting newcomer
  • *
  • Posts: 5
Re: New to C and CODEBLOCKS
« Reply #5 on: April 22, 2020, 08:04:58 pm »
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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: New to C and CODEBLOCKS
« Reply #6 on: April 22, 2020, 08:47:33 pm »
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!]

Offline bioya1

  • Single posting newcomer
  • *
  • Posts: 5
Re: New to C and CODEBLOCKS
« Reply #7 on: April 22, 2020, 08:58:26 pm »
Will try. Many thanks for pointing me in this direction.

 :)