Thanks - I've started getting a bit grumpy about coding rules that come without any explanation of why you should do something (simply saying something is "best practise" often being the worst "explanation" of all).
Rather than writing:
if (argc == 3) {
if (fname) {
/* Do stuff */
} else {
printf ("File name cannot be null");
}
} else {
printf ("Wrong number of arguments");
}
I would write: if (argc != 3) {
printf ("Wrong number of arguments");
} else if (!fname) {
printf ("File name cannot be null");
} else {
/* Do stuff */
} if (argc != 3) {
printf ("Wrong number of arguments");
// throw an exception or return NULL or something
}
if (!fname) {
printf ("File name cannot be null");
// throw an exception or return NULL or something
}
/* Do stuff */
The important thing, to my mind, is the absence of an else block.