/* * Do we need an alert? if so schedule one. */ int determine_if_alarm_needed(int num) { // Copy the right event across memcpy(&event, &events[num], sizeof(Event)); // Alarms set int alarms_set = 0; // Ignore all day events if (event.all_day) { return alarms_set; } // Is the event today if (is_date_today(event.start_date) == false) { return alarms_set; } // Compute the event start time as a figure in ms int time_position = 9; if (event.start_date[5] != '/') time_position = 6; int hour = a_to_i(&event.start_date[time_position],2); int minute_position = time_position + 3; if (event.start_date[time_position + 1] == ':') minute_position = time_position + 2; int minute = a_to_i(&event.start_date[minute_position],2); uint32_t event_in_ms = (hour * 3600 + minute * 60) * 1000; // Get now as ms time_t rawtime; time(&rawtime); struct tm *time = localtime(&rawtime); uint32_t now_in_ms = (time->tm_hour * 3600 + time->tm_min * 60 + time->tm_sec) * 1000; // Work out the alert interval int32_t alert_event = event_in_ms - now_in_ms; // If this is negative then we are after the alert period if (alert_event >= 0) { // Make sure we have the resources for another alert alerts_issued++; if (alerts_issued > MAX_ALLOWABLE_ALERTS) return alarms_set; // Queue alert queue_alert(num, event.title, alert_event); alarms_set++; } return alarms_set; }
main() { char temp[20]; int result; fgets(temp, 20, stdin); while(a_to_i(temp) != 0) { result = a_to_i(temp); printf("%d\n",factorial(result)); fgets(temp, 20, stdin); } printf("1\n"); }
void test_a_to_i() { int result, expected_result; result = a_to_i("7", 2); expected_result = 7; check_int(result, expected_result); result = a_to_i("4211", 5); expected_result = 4211; check_int(result, expected_result); result = a_to_i(" -2 ", 5); expected_result = -2; check_int(result, expected_result); }
main() { char* input; int result, fact; unsigned int num; result = 1; while (result != 0) { input = malloc(21); fgets(input, 20, stdin); result = a_to_i(input); if (result > 0) { num = result; fact = factorial(num); printf("%d\n", fact); } else { num = 0; fact = factorial(num); printf("%d\n", fact); free(input); break; } free(input); } return; }
void assignment(ecc_context *ctx, const char *variable) { const char *token; unsigned int var_pos; int number; /* advance past variable */ ctx->lex_advance(ctx, str_nlen(variable, TOKEN_MAX)); token = ctx->lex_look_ahead(ctx); if (token[0] != '=') { err_msg("token '"); err_msg(token); err_msg("' is not an '='\n"); die(); } ctx->lex_advance(ctx, str_nlen(token, TOKEN_MAX)); token = ctx->lex_look_ahead(ctx); if (is_number(token[0])) { number = a_to_i(token, str_nlen(token, TOKEN_MAX)); ctx->lex_advance(ctx, str_nlen(token, TOKEN_MAX)); var_pos = ctx->stack_name_pos(ctx, variable); ctx->output_stack_assign_int(ctx, var_pos, number); } else { err_msg("not supported\n"); die(); } }
void factor(ecc_context *ctx, const char *token) { int number; unsigned int negate; if (token[0] == '(') { ctx->lex_advance(ctx, 1); token = ctx->lex_look_ahead(ctx); expression(ctx, token); /* eat close paren */ ctx->lex_advance(ctx, 1); } else { if ((token[0] == '-') && (str_nlen(token, TOKEN_MAX) == 1)) { negate = 1; ctx->lex_advance(ctx, 1); token = ctx->lex_look_ahead(ctx); } else { negate = 0; } number = a_to_i(token, str_nlen(token, TOKEN_MAX)); if (negate) { number = -number; } ctx->lex_advance(ctx, str_nlen(token, TOKEN_MAX)); ctx->output_term(ctx, number); } }
/* * Alter the raw date and time returned by iOS to be really nice on the eyes at a glance */ void modify_calendar_time(char *output, int outlen, char *date, bool all_day) { // When "Show next events" is turned off in the app: // MM/dd // When "Show next events" is turned on: // MM/dd/yy // If all_day is false, time is added like so: // MM/dd(/yy) H:mm // If clock style is 12h, AM/PM is added: // MM/dd(/yy) H:mm a // Build a list of dates and day names closest to the current date ensure_close_day_cache(); int time_position = 9; if (date[5] != '/') time_position = 6; // Find the date in the list prepared char temp[12]; bool found = false; for (int i=0; i < 7; i++) { if (strncmp(g_close[i].date, date, 5) == 0) { strncpy(temp, g_close[i].dayName, sizeof(temp)); found = true; break; } } // If not found then show the month and the day if (!found) { time_t now = time(NULL); struct tm *now_tm = localtime(&now); struct tm fiddle; memcpy(&fiddle, now_tm, sizeof(fiddle)); fiddle.tm_mday = a_to_i(&date[3],2); fiddle.tm_mon = a_to_i(&date[0],2) - 1; strftime(temp, sizeof(temp), "%b %e -", &fiddle); } // Change the format based on whether there is a timestamp if (all_day) snprintf(output, outlen, "%s %s", temp, ALL_DAY); else snprintf(output, outlen, "%s %s", temp, &date[time_position]); }
int main () { char *number = " +348"; printf ("%d\n", a_to_i (number)); return 0; }
main(){ char input[] = ""; unsigned int ascii = 1; unsigned int fact = 1; do{ fgets(input, 20, stdin); ascii = a_to_i(input); fact = factorial(ascii); printf("%d\n", fact); if(fact == 1) break; }while(ascii != 0); return 0; }
main(){ char* str; int i,total=0; fgets(str, 20, stdin); int a_to_i(char* str){ for(i=0;i<strlen(str)-2;i++){ if((int)str[i]==0){ return total; break; } else{ total = total*10 + ((int)str[i]-48); } } printf("%d\n",total); } a_to_i(str); }
/* * Do we need an alert? if so schedule one. */ int determine_if_alarm_needed(int num) { // Copy the event for easy access Event event; memcpy(&event, &g_events[num], sizeof(Event)); // Alarms set int alarms_set = 0; // Ignore all day events if (event.all_day) { return alarms_set; } // Is the event today if (is_date_today(event.start_date) == false) { return alarms_set; } // Does the event have an alarm if (event.alarms[0] == -1 && event.alarms[1] == -1) { return alarms_set; } // Compute the event start time as a figure in ms int time_position = 9; if (event.start_date[5] != '/') time_position = 6; int hour = a_to_i(&event.start_date[time_position],2); int minute_position = time_position + 3; if (event.start_date[time_position + 1] == ':') minute_position = time_position + 2; int minute = a_to_i(&event.start_date[minute_position],2); uint32_t event_in_ms = (hour * 3600 + minute * 60) * 1000; // Get now as ms PblTm time; get_time(&time); uint32_t now_in_ms = (time.tm_hour * 3600 + time.tm_min * 60 + time.tm_sec) * 1000; // First alart if (event.alarms[0] != -1) { // Work out the alert interval int32_t alert_event = event_in_ms - now_in_ms - (event.alarms[0] * 1000); // If this is negative then we are after the alert period if (alert_event >= 0) { // Make sure we have the resources for another alert g_alerts_issued++; if (g_alerts_issued > MAX_ALLOWABLE_ALERTS) return alarms_set; // Queue alert queue_alert(num, event.alarms[0], event.title, alert_event, event.has_location ? event.location : ""); alarms_set++; } } // Second alart if (event.alarms[1] != -1) { // Work out the alert interval int32_t alert_event = event_in_ms - now_in_ms - (event.alarms[1] * 1000); // If this is negative then we are after the alert period if (alert_event >= 0) { // Make sure we have the resources for another alert g_alerts_issued++; if (g_alerts_issued > MAX_ALLOWABLE_ALERTS) return alarms_set; // Queue alert queue_alert(num + 15, event.alarms[1], event.title, alert_event, event.has_location ? event.location : ""); alarms_set++; } } return alarms_set; }
/* * Timer handling. Includes a hold off for a period of time if there is resource contention */ void handle_calendar_timer(void *cookie) { // Show the alert and let the world know if ((int)cookie >= ALERT_EVENT && (int)cookie <= ALERT_EVENT + MAX_EVENTS) { int num = (int)cookie - ALERT_EVENT; if (timer_rec[num].active == false) return; // Already had the data for this event deleted - cannot show it. timer_rec[num].active = false; for (int i = num + 1; i < max_entries; i++) { if (timer_rec[i].active == true) { handle_calendar_timer((void *)100 + i); vibes_short_pulse(); light_enable_interaction(); return; } } //draw_date(); return; } if ((int)cookie >= 100 && (int)cookie <= 100 + MAX_EVENTS) { int num = (int)cookie - 100; if (timer_rec[num].active == false) return; // Already had the data for this event Event event = events[num]; // Compute the event start time as a figure in ms int time_position = 9; if (event.start_date[5] != '/') time_position = 6; int hour = a_to_i(&event.start_date[time_position],2); int minute_position = time_position + 3; if (event.start_date[time_position + 1] == ':') minute_position = time_position + 2; int minute = a_to_i(&event.start_date[minute_position],2); uint32_t event_in_ms = (hour * 3600 + minute * 60) * 1000; // Get now as ms time_t rawtime; time(&rawtime); struct tm *time = localtime(&rawtime); uint32_t now_in_ms = (time->tm_hour * 3600 + time->tm_min * 60 + time->tm_sec) * 1000; // Work out the alert interval int32_t alert_event = event_in_ms - now_in_ms; // If this is negative then we are after the alert period if (alert_event >= 0) { set_relative_desc(num, alert_event); display_event_text(timer_rec[num].event_desc, timer_rec[num].relative_desc); if (alert_event == 0) { timer_rec[num].handle = app_timer_register(30000, handle_calendar_timer, (void *)ALERT_EVENT + num); vibes_double_pulse(); light_enable_interaction(); } else if (alert_event > 0) { timer_rec[num].handle = app_timer_register(60000 - time->tm_sec * 1000, handle_calendar_timer, (void *)100 + num); } } return; } // Server requests if ((int)cookie != REQUEST_CALENDAR_KEY) return; // If we're going to make a call to the phone, then a dictionary is a good idea. DictionaryIterator *iter; app_message_outbox_begin(&iter); // We didn't get a dictionary - so go away and wait until resources are available if (!iter) { // Can't get an dictionary then come back in a second app_timer_register(1000, handle_calendar_timer, (void *)cookie); return; } // Make the appropriate call to the server if ((int)cookie == REQUEST_CALENDAR_KEY) { calendar_request(iter); app_timer_register(REQUEST_CALENDAR_INTERVAL_MS, handle_calendar_timer, (void *)cookie); } }