// Friday13.m Copyright (c) Kari Laitinen // http://www.naturalprogramming.com // 2013-07-15 Objective-C version of this file was created. // 2013-07-15 Last modification. #include #import #import "class_isodate_oc.h" int main( void ) { NSAutoreleasePool* autorelease_pool = [ [ NSAutoreleasePool alloc ] init ] ; char given_date_as_c_string[ 20 ] ; printf( "\n This program can print you a list of 10 dates" "\n that are Fridays and 13th days of a month." "\n Please, type in a date from which you want" "\n the calculation to begin. Type in the date" "\n in form YYYY-MM-DD: " ) ; scanf( "%s", given_date_as_c_string ) ; NSString* given_date_as_nsstring = [ NSString stringWithUTF8String: given_date_as_c_string ] ; ISODate* date_to_increment = [ [ ISODate alloc ] init_with_string: given_date_as_nsstring ] ; int number_of_friday13_dates_to_print = 10 ; printf( "\n It is a common belief that you may have" "\n bad luck on the following dates:\n" ) ; while ( number_of_friday13_dates_to_print > 0 ) { while ( [ date_to_increment index_for_day_of_week ] != 4 || [ date_to_increment day ] != 13 ) { [ date_to_increment increment ] ; } // Now we have found a date that is Friday the 13th. // Let's print the date. NSString* text_to_print = [ NSString stringWithFormat: @"\n %@, %@", date_to_increment, [ date_to_increment get_day_of_week ] ] ; printf( "%s", [ text_to_print UTF8String ] ) ; [ date_to_increment increment ] ; number_of_friday13_dates_to_print -- ; } printf( "\n\n" ) ; [ autorelease_pool drain ] ; } /* Here is a sample compilation and execution of this program: user$ gcc Friday13.m -o runnablefile.out -framework Foundation user$ ./runnablefile.out This program can print you a list of 10 dates that are Fridays and 13th days of a month. Please, type in a date from which you want the calculation to begin. Type in the date in form YYYY-MM-DD: 2013-07-15 It is a common belief that you may have bad luck on the following dates: 2013-09-13, Friday 2013-12-13, Friday 2014-06-13, Friday 2015-02-13, Friday 2015-03-13, Friday 2015-11-13, Friday 2016-05-13, Friday 2017-01-13, Friday 2017-10-13, Friday 2018-04-13, Friday */