views:

241

answers:

3

Let say I have 5 small piece of codes in C. Every time I want to test each piece of code, I have to repeat this process:

#include <stdio.h>
int main()
{
   // code piece go into here
   return 0;
}

Is there way that I don't have to do this 5 times? I'm using Code::Blocks, that means I have to create 5 different projects, which I believe not necessary because each piece of code is small.

A: 

Would template files or copying and pasting be too difficult for some reason?

Azeem.Butt
In C, is there template? Please show me an example if u can. Thanks much.
tsubasa
I believe the templates in question would be a feature of your editor... you could have a template for a header file, another for an entry point (including your main function), etc. When you creat a new file, your editor pre-populates it with the configured template.
grossvogel
+2  A: 

Is this really so hard? Every program you run needs a main function, and the text you've pasted there isn't very long. Also, people expect to see a main function in C/C++ programs. If you template this out somehow, you're just going to make your code confusing.

If the issue is that you have to make a project for every test you want to build, then I would guess you are not using your IDE correctly. Is there not a multi-target project type that lets you have multiple test programs without all the extra project files? If there is not, then perhaps you should be using a different IDE.

tgamblin
Yes, multi-target project is something that i'm really looking for. Anybody knows how to do it in Code::Blocks?
tsubasa
A: 

Use a good editor with code templates. Most feature-full editors (Emacs, vi, Scite, Textmate, or even MSVC if that's your cup of tea) have some support for them. This way, writing this boring template every time will take only a fraction of the second.

Eli Bendersky
Thanks, this helps!
tsubasa