Author Topic: How do I, in a project, call main.c something else and have it still run?  (Read 12359 times)

Offline yarly

  • Single posting newcomer
  • *
  • Posts: 8
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?

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7665
    • My Best Post
Re: How do I, in a project, call main.c something else and have it still run?
« Reply #1 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.

C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline papagym

  • Multiple posting newcomer
  • *
  • Posts: 41
Re: How do I, in a project, call main.c something else and have it still run?
« Reply #2 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.

Offline yarly

  • Single posting newcomer
  • *
  • Posts: 8
Re: How do I, in a project, call main.c something else and have it still run?
« Reply #3 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
« Last Edit: September 21, 2015, 10:42:39 pm by yarly »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: How do I, in a project, call main.c something else and have it still run?
« Reply #4 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.
(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 Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7256
Re: How do I, in a project, call main.c something else and have it still run?
« Reply #5 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.

Offline papagym

  • Multiple posting newcomer
  • *
  • Posts: 41
Re: How do I, in a project, call main.c something else and have it still run?
« Reply #6 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