int mcq(const char *qn, const char *choices, int arraySize, int preset) { int i, len, ans; int invalid = 1; int qlen; char response[MINI_BUFSZ]; char *str; qlen = strlen(qn) + 4; fflush(stdout); do { print_repeat('-', qlen); printf("%s==> %s", color.byellow, color.nocolor); printf("%s%s%s\n", color.bold, qn, color.nocolor); print_repeat('-', qlen); printf("%s==> %s", color.byellow, color.nocolor); str = fgets(response, MINI_BUFSZ, stdin); str = strtrim(str); len = strlen(str); if (len == 0) { return preset; } /* Get response */ ans = check_mcq_response(str, sizeof(char), choices, arraySize); } while (ans == -1); return ans; }
int main(){ int n, i = 0; scanf("%d", &n); for(; i < n; i++){ print_repeat(' ', i); print_repeat('#', 2 * (n - i) - 1); puts(""); } return 0; }
/* Question which requires a y/n answer. * returns 0 for n, 1 for y */ static int question(int preset, const char *fmt, va_list args) { int i, ret, len, qlen; char response[MINI_BUFSZ]; char buf[PATH_MAX]; char *str; vsnprintf(buf, PATH_MAX, fmt, args); qlen = strlen(buf) + 4 + 6; fflush(stdout); do { print_repeat('-', qlen); printf("%s==> %s%s", color.byellow, color.nocolor, color.bold); printf("%s", buf); if (preset) { printf(" [Y/n]"); } else { printf(" [y/N]"); } printf("\n"); print_repeat('-', qlen); printf("%s==> %s", color.byellow, color.nocolor); str = fgets(response, sizeof(response), stdin); str = strtrim(str); len = strlen(str); if (!len) { return preset; } else { if (!strcasecmp(str, "n") || !strcasecmp(str, "no")) { print_repeat('-', qlen); return 0; } else if (!strcasecmp(str, "y") || !strcasecmp(str, "yes")) { print_repeat('-', qlen); return 1; } } } while (1); }
static void print_session(sdp_printer_t *p, sdp_session_t const *sdp) { p->pr_ok = 1; if (p->pr_ok && sdp->sdp_version) print_version(p, sdp->sdp_version); if (p->pr_ok && sdp->sdp_origin) print_origin(p, sdp->sdp_origin); if (p->pr_ok && sdp->sdp_subject) print_subject(p, sdp->sdp_subject); if (p->pr_ok && sdp->sdp_information) print_information(p, sdp->sdp_information); if (p->pr_ok && sdp->sdp_uri) print_uri(p, sdp->sdp_uri); if (p->pr_ok && sdp->sdp_emails) print_emails(p, sdp->sdp_emails); if (p->pr_ok && sdp->sdp_phones) print_phones(p, sdp->sdp_phones); if (p->pr_ok && sdp->sdp_connection) print_connection(p, sdp->sdp_connection); if (p->pr_ok && sdp->sdp_bandwidths) print_bandwidths(p, sdp->sdp_bandwidths); if (p->pr_ok) print_time(p, sdp->sdp_time); if (p->pr_ok && sdp->sdp_time) { if (p->pr_ok && sdp->sdp_time->t_repeat) print_repeat(p, sdp->sdp_time->t_repeat); if (p->pr_ok && sdp->sdp_time->t_zone) print_zone(p, sdp->sdp_time->t_zone); } if (p->pr_ok && sdp->sdp_key) print_key(p, sdp->sdp_key); if (p->pr_ok && sdp->sdp_charset) print_charset(p, sdp->sdp_charset); if (p->pr_ok && sdp->sdp_attributes) print_attributes(p, sdp->sdp_attributes); if (p->pr_ok && sdp->sdp_media) print_media(p, sdp, sdp->sdp_media); }
// prints generated code // set bf to true to print valid bf, or false to print bytecode void print_code(FILE* f, Code* opt, size_t len, bool bf) { size_t i; for (i = 0; i < len; i++) { Code* c = opt + i; if (c->func == bf_end) { break; } else if (c->func == bf_lb) { fputc('[', f); } else if (c->func == bf_rb || c->func == bf_rb_nop) { fputc(']', f); } else if (c->func == bf_putc) { fputc('.', f); } else if (c->func == bf_getc_unc || c->func == bf_getc_val) { fputc(',', f); } else if (c->func == bf_left) { fputc('<', f); } else if (c->func == bf_right) { fputc('>', f); } else if (c->func == bf_plus) { fputc('+', f); } else if (c->func == bf_minus) { fputc('-', f); } else if (c->func == bf_nop) { // nop } else if (c->func == bf_zero) { if (bf) fprintf(f, "[-]"); else putc('z', f); } else if (c->func == bf_add) { int inc = (signed char) c->inc; if (bf) { fprintf(f, "[-"); print_repeat(f, c->shift, '>', '<'); print_repeat(f, inc, '+', '-'); print_repeat(f, -c->shift, '>', '<'); putc(']', f); } else { fprintf(f, "a(%d,%d)", inc, c->shift); } } else if (c->func == bf_inc) { int inc = (signed char) c->inc; if (bf) { print_repeat(f, inc, '+', '-'); } else fprintf(f, "i(%d)", inc); } else if (c->func == bf_shift) { if (bf) { print_repeat(f, c->shift, '>', '<'); } else fprintf(f, "s(%d)", c->shift); } else if (c->func == bf_inc_shift) { int inc = (signed char) c->inc; if (bf) { print_repeat(f, inc, '+', '-'); print_repeat(f, c->shift, '>', '<'); } else fprintf(f, "c(%d,%d)", inc, c->shift); } else if (c->func == bf_inc_shift_lb) { int inc = (signed char) c->inc; if (bf) { print_repeat(f, inc, '+', '-'); print_repeat(f, c->shift, '>', '<'); fputc('[', f); } else fprintf(f, "c(%d,%d)[", inc, c->shift); } else if (c->func == bf_inc_shift_rb) { int inc = (signed char) c->inc; if (bf) { print_repeat(f, inc, '+', '-'); print_repeat(f, c->shift, '>', '<'); fputc(']', f); } else fprintf(f, "c(%d,%d)]", inc, c->shift); } else { fputc('?', f); } } fputc('\n', f); }