by arethuza · 15y ago · 0 comments
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.