static void readBlob(test_info *t) { SQLRETURN rc; char buf[4096]; SQLLEN len, total = 0; int i = 0; int check; printf(">> readBlob field %d\n", t->num); while (1) { i++; rc = CHKGetData(t->num, SQL_C_BINARY, (SQLPOINTER) buf, (SQLINTEGER) sizeof(buf), &len, "SINo"); if (rc == SQL_NO_DATA || len <= 0) break; if (len > (SQLLEN) sizeof(buf)) len = (SQLLEN) sizeof(buf); printf(">> step %d: %d bytes readed\n", i, (int) len); check = check_chars(buf, len, t->gen1 + total, t->gen2); if (!check) { fprintf(stderr, "Wrong buffer content\n"); dump(stderr, " buf ", buf, len); failed = 1; } total += len; } printf(">> total bytes read = %d \n", (int) total); if (total != 10000) { fprintf(stderr, "Wrong buffer length, expected 20000\n"); failed = 1; } }
int check_chars(char *s, int i, int n, int m) { if (i == m) { /* basecase: whole string checked, string is palindrome */ return 1; } if (s[i] != s[n]) { /* basecase: chars do not match, string not palindrome */ return 0; } /* else */ return check_chars(s, i + 1, n - 1, m); }
int is_palindrome(char *s) { int n; int m; n = find_length(s, 0) - 1; if (n % 2 == 0) { /*if length is odd */ m = n/2; } else { /* length is even */ m = n/2 + 1; } return check_chars(s, 0, n, m); }
void test_str_ncpy() { const char *src = "foo"; char dest[80]; char *result, *expected_result; dest[60] = 'X'; check_unsigned_int(sizeof(dest), 80); check_char(dest[60], 'X'); result = str_ncpy(dest, src, sizeof(dest)); check_strs(dest, src, "1"); check_ptrs(result, dest, "2"); check_chars(dest[60], '\0', "should null-out rest of buffer"); expected_result = strncpy(dest, src, sizeof(dest)); check_strs(dest, src, "3"); check_ptrs(result, expected_result, "4"); }
int check_tetriminos(t_list *data) { char *s; size_t i; i = 0; if (!data) return (0); while (data) { s = data->content; if (check_chars(s, 0) == 0 || check_pattern(s, 0, 0, 0) == 0) return (0); if (i > 26) return (0); data = data->next; i++; } return (1); }
int main(int ac, char **av) { int i; i = 0; if (ac != 10 || count_chars(av) == 0) fprintf(stderr, "%s\n", usage); else { while (++i < 10) { if (!check_chars(av[i])) { fprintf(stderr, "%s\n", "sudoku need 10 row"); return (0); } } if (resolve(av, 0)) display_tab(av); else fprintf(stderr, "%s\n", "resolve failed"); } return (0); }
static gboolean handle_backspace( AutocloseUserData *data, ScintillaObject *sci, gchar ch, gchar *ch_left, gchar *ch_right, GdkEventKey *event, gint indent_width) { gint pos = sci_get_current_position(sci); gint end_pos; gint line_start, line_end, line; gint i; if (!ac_info->delete_pairing_brace) return AC_CONTINUE_ACTION; ch = char_at(sci, pos - 1); if (!check_chars(sci, ch, ch_left, ch_right)) return AC_CONTINUE_ACTION; if (event->state & GDK_SHIFT_MASK) { if ((ch_left[0] == ch || ch_right[0] == ch) && ac_info->bcksp_remove_pair) { end_pos = sci_find_matching_brace(sci, pos - 1); if (-1 == end_pos) return AC_CONTINUE_ACTION; sci_start_undo_action(sci); line_start = sci_get_line_from_position(sci, pos); line_end = sci_get_line_from_position(sci, end_pos); SSM(sci, SCI_DELETERANGE, end_pos, 1); if (end_pos < pos) pos--; SSM(sci, SCI_DELETERANGE, pos - 1, 1); /* remove indentation magick */ if (char_is_curly_bracket(ch)) { if (line_start == line_end) goto final; if (line_start > line_end) { line = line_end; line_end = line_start; line_start = line; } if (blank_line(sci, line_start)) { delete_line(sci, line_start); line_end--; } else line_start++; if (blank_line(sci, line_end)) delete_line(sci, line_end); line_end--; /* unindent */ for (i = line_start; i <= line_end; i++) { unindent_line(sci, i, indent_width); } } final: sci_end_undo_action(sci); return AC_STOP_ACTION; }