r/cprogramming • • 25d ago

Code initializer program.

To be honest, that's the best name I could think of.

You know when you start writing a file you have to type the usual

#include <stdio.h>

int main(int argc, char* argv[]){

  return 0;
}

Well this program makes it for you. It's may sound very simple, but at least it saves some time.

Source code:https://pastebin.com/yMj7njqC(Sorry github won't create an account for me, it says invalid domain?)

2 Upvotes

14 comments sorted by

7

u/GrainWeevil 25d ago

Nice job!

If you want to extend this a bit, a good next step might be to check if the file exists before writing it, so you don't accidentally overwrite something. You could try asking the user to confirm if they're sure they want to continue.

5

u/MasterpieceBusy7220 25d ago

What if I don’t want to include stdio

4

u/onlyonequickquestion 25d ago edited 25d ago

If you want to make this more useful and beef it up a bit, maybe try generating build system scripts as well, have a switch for make, cmake, ninja, whatever people are using these days, and different compilers. That way, you can just run your generator, run make, and be off to the races 

4

u/chibiace 25d ago

yeah i made my own thing that just copies the template files for the selected language to the current directory, im only really saving time on the Makefile because i want to have all that stuff standardized between projects and im not sure i could remember all of it from memory.

though i actually like writing out main.c, its like stretching before a run.

1

u/Puzzled-Garage584 25d ago

Nice. If you extend it put -Wall -Wextra -fsanitize=address in a generated Makefile, typing main takes 4 seconds but a segfault without ASan takes the whole evening. The github invalid domain thing is probably your email, try another one.

1

u/nandezftw 21d ago

Great program. Would be a neat addition if you could add more arguments at a time.

-1

u/whatThePleb 25d ago

Just use a proper IDE..

1

u/Paul_Pedant 24d ago

Exactly. And if I am writing a 400-line C program, optimizing 1% of it does not really help much. That part is more or less just a warm-up for my fingers.

0

u/CS_70 25d ago

If only we could develop a program to which you tell what you want in enough detail in natural language, and it made it for you, imagine the time it would save!!

:D

0

u/nandezftw 21d ago

Ever get tired of being miserable?