On Jan 2, 6:26 pm, ssylee <staniga...@gmail.com> wrote:
> const char* getDayOfWeekName(int inDayIndex)
> {
> static const char* const days[] =
> { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
> "Saturday" };
> assert(inDayIndex >= 1 && inDayIndex <= 7);
> return days[inDayIndex - 1];
>
> }
>
> However, I've come across another problem of not being able to use
> assert. Therefore, I've come up with a method that gets around using
> assert, but not sure if it's appropriate:
>
> const char* getDayOfWeekName(int inDayIndex)
> {
> static const char* const days[] =
> { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
> "Saturday" };
> if (!(inDayIndex >= 1 && inDayIndex <= 7)){
> return "Error";
> }
> return days[inDayIndex - 1];
>
> }
If you really want to go this way then you should return 0 and not
"Error". Otherwise the user of your function has to do a strcmp to
determine if there was an error which is very expensive.
Regards,
Ivan Novick
http://www.0x4849.net