1. Methods to Improve program efficiency and methods to improve program efficiency
1And if statements handle errors:
If (ch> = '0' & ch <= '9 ')
{
/* Process the code normally */
}
Else
{
/* Output error message */
Printf ("error... \ n ");
Return (FALSE );
}
This structure is very bad, especially if the "normal code processing" is very long, it is best not to use else in this case. First Judge the error, such:
If (ch <'0' | ch> '9 ')
{
/* Output error message */
Printf ("error... \ n ");
Return (FALSE );
}
/* Process the code normally */
......
Isn't this structure clear? Highlight the wrong conditions so that when others use your function, they can see invalid conditions at first glance, so they will be more subconsciously avoided.
2Avoid unnecessary function calls
Consider the following two functions:
Void str_print (char * str)
{
Int I;
For (I = 0; I <strlen (str); I ++)
{
Printf ("% c", str [I]);
}
}
Void str_print1 (char * str)
{
Int len;
Len = strlen (str );
For (I = 0; I <len; I ++)
{
Printf ("% c", str [I]);
}
}
Note: it is better to call more than 1st functions.
3,