A function should be anythign that represents a logical unit.
Originally Posted by Hackstorix
E.g. the area of a circle, or other geometrical shape. The maximum, minimum, or average in a list. Loading a data base of employees from disk. Paying the employees. Saving the updated data with the new pay information back to disk.
There are some tricks. Don't be afraid to softcode a fucntion parameter, then hardcode the argument. Say you input a line consisting of a list of numbers, separated by commas. You can count the numbers by counting the commas.
will do this for you. However the comma will be hardcoded, higher up.
int strcount(char *str, char ch)
int answer = 0;
The second trick is to use pointers a lot. Virtually all of you C functions will pass information to and from caller, using pointers,usually pointers to structures or arrays of structures.
Nnumbers = strcount(line, ',') + 1;
Also use malloc() a lot. Mostly there won't be a natural limit to the
amount of data you are operating on. By using malloc(), you allow the program to grow, until the machine runs out of memory.