Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: yarly on September 19, 2015, 01:35:22 pm

Title: How do I, in a project, call main.c something else and have it still run?
Post by: yarly on September 19, 2015, 01:35:22 pm
When I create a project in C::B,  I choose  console application, C

And it creates a project with the file main.c

How can I get a different filename there?
Title: Re: How do I, in a project, call main.c something else and have it still run?
Post by: stahta01 on September 19, 2015, 01:40:11 pm
When I create a project in C::B,  I choose  console application, C

And it creates a project with the file main.c

How can I get a different filename there?

These are the steps I use; if you need detailed steps please ask.

1. Save the file main.c with the name I want it to have.
2. Add the saved file to the project
3. Remove main.c from the project

There are other methods; but, this is the easiest one I know of.

Tim S.

Title: Re: How do I, in a project, call main.c something else and have it still run?
Post by: papagym on September 20, 2015, 03:26:17 am
Your subject and post are not real clear so it's not clear what you are trying to do.

If you're a newbie to programming.  I suggest you learn by reading some tutorials on C or C++.
 
You can not change the name of the main function in C or C++.  All programming starts from the main function.  However you can change what is in the body of the main function does, that is what's located between the curly braces.

If you trying to change the name of the project ...main.c... all you need to do is rename it.
Title: Re: How do I, in a project, call main.c something else and have it still run?
Post by: yarly on September 21, 2015, 10:39:14 pm
Thanks. What Stah suggested, worked.

@papa
I know how to write a C program. I am not trying to change the name of the 'main' function. I am not talking about the main function. I am talking about the filename, as I said, main.c  If you try writing a C program in vi, and compiling it with gcc, or even doing so with C::B outside of a project,  you see the filename can be anything. Though for projects, code::blocks defaults to calling the file main.c Of my 3 line question, lines 2 and 3 show that I was just talking about filenames not the main function.

My mistake was an IDE mistake - not "adding the file to the project".   I see no rename option within codeblocks(if I saw it I could take main.c that is already added and rename it).   So now i'm getting it to work with file..new..empty file..yes..[name it]..save..ok  (or I suppose I can right click the project and do add file).

Ta
Title: Re: How do I, in a project, call main.c something else and have it still run?
Post by: oBFusCATed on September 22, 2015, 11:41:41 am
There is an easier way - close the file, find it in the project manager and right click -> rename.
Title: Re: How do I, in a project, call main.c something else and have it still run?
Post by: Jenna on September 22, 2015, 07:35:39 pm
Or create an empty project and create any files you want with "File -> New".
C::B asks you whether to add it to the project in this case.
Note: you need to type the file-ending also.
Title: Re: How do I, in a project, call main.c something else and have it still run?
Post by: papagym on September 25, 2015, 03:08:15 am
Yarly,
 
If you have C programs you want to use in C++ all you have to do is copy the C programs data into the buffer and paste it into a new file into the code::blocks editor.  Remember your just copying and pasting the contents of the file, not it's name. 

C::B has a few way to start a new file or project look at the others replies here to help you.

You can use New>Empty File or open a new project.
Of course when you go to compile the program with C::B you have to give it a name. You may use any name you want , just remember to add the .cpp extension to it.

If the programs don't compile the syntax my need some slight changes to work with C++.

If your still having problem you need to supply more details