To me, programming isn't really about practical problem solving as much it is about learning and figuring things out. I think general structuring practices are interesting: "how many comments should you leave?", etc. They tend to deal with the more human aspect of writing programs.
In C, you have to either create your separate functions (outside of main) right off the bat, or prototype them and put their code after the main function. Since the main function is in every C program, it would make more sense IMO to use the second type of structure:
Code:
#include <stdio.h>
/* function prototype */
void prompt();
int main()
{
int loop;
char input[32];
loop=0;
while(loop<5)
{
prompt();
fgets(input,32,stdin);
loop=loop+1;
}
return(0);
}
/* Display prompt */
void prompt(void)
{
printf("C:\\DOS> ");
}
However, when i look at the source code for programs that I use, i see that they prefer not to prototype the non-main functions, and just put them before main. After, it is less typing. I would think that putting the main function before all the other ones in the file would more sense for readability, but i am not much of a C programmer. Are there also other benefits to putting your non-main functions after main?
The code above is just an example from a book, btw, to demonstrate what I'm talking about, it is pretty silly/pointless outside of an educational exercise.