If that's an interesting attempt at getting someone to do your homework, perhaps I bit. It made for an interesting diversion for me.
But since such things are frowned upon, I did make it something that it would be difficult to explain to an instructor if grades might be involved.
And this doesn't shoot for speed.
* Find the next or previous Friday the 13th.
* @param target pointer to tm structure containing result
* @param start pointer to tm structure containing beginning date
* @param direction nonnegative indicates forward, negative indicates backward
* @return nonzero if the date was found and the target successfully filled
int FridayThe13th(struct tm *target, const struct tm *start, int direction)
const int move = direction < 0 ? -1 : 1;
while ( *target = *start, target->tm_mon += move,
(guess = mktime(target)) != (time_t)-1 &&
(start = localtime(&guess)) != NULL &&
target->tm_wday != 5 );
And in fact, this doesn't handle some UB very well; that went out with the "compacting".