void start_engine( char *_string ) { int i, j, k; RAW_DATA.RAW_STRING = _string; RAW_DATA.RAW_STRING_LENGTH = get_string_length( RAW_DATA.RAW_STRING ); RAW_DATA.APPEND_NEEDED = is_append_needed( RAW_DATA.RAW_STRING_LENGTH ); char _eight_string_array[ ( RAW_DATA.RAW_STRING_LENGTH + RAW_DATA.APPEND_COUNT ) ][ 9 ]; char _eight_bit_string[ ( ( RAW_DATA.RAW_STRING_LENGTH + RAW_DATA.APPEND_COUNT ) * 9 ) + 1 ]; char *_char_temp; _char_temp = RAW_DATA.RAW_STRING; for( i=0; i<( RAW_DATA.RAW_STRING_LENGTH + RAW_DATA.APPEND_COUNT ); i++ ) { if( i >= RAW_DATA.RAW_STRING_LENGTH ) { for( j=0; j<9; j++ ) { if( j == 8 ) { _eight_string_array[ i ][ j ] = '\0'; } else { _eight_string_array[ i ][ j ] = '0'; } } } else { char *_char_temp_local; _char_temp_local = get_eight_bit_string( ( int )*_char_temp ); j = 0; while( *_char_temp_local != '\0' ) { _eight_string_array[ i ][ j ] = *_char_temp_local; _char_temp_local++; j = j + 1; } _eight_string_array[ i ][ j ] = '\0'; _char_temp++; } } i = 0; j = 0; k = 0; for( i=0; i<( RAW_DATA.RAW_STRING_LENGTH + RAW_DATA.APPEND_COUNT ); i++ ) { for( j=0; j<get_string_length( _eight_string_array[ i ] ); j++ ) { _eight_bit_string[ k ] = _eight_string_array[ i ][ j ]; k++; } } _eight_bit_string[ k ] = '\0'; segment_and_get_base64_index( get_string_length( _eight_bit_string ), _eight_bit_string ); }
char *get_eight_bit_string( int _ASCII ) { char *_return_char; char _binary_string[ 9 ]; int _while_loop_count, _mod_value; int i = 0, j = 0, k = 0; while( 1 ) { _mod_value = _ASCII % 2; if( _mod_value == 0 ) { _binary_string[ i ] = '0'; _ASCII = _ASCII / 2; if( _ASCII == 0 ) { break; } else { i = i + 1; continue; } } else { _binary_string[ i ] = '1'; _ASCII = _ASCII / 2; if( _ASCII == 0 ) { break; } else { i = i + 1; continue; } } } j = 8 - i; for( k=1; k<=j; k++ ) { i = i + 1; _binary_string[ i ] = '0'; } _binary_string[ i ] = '\0'; for( i=0; i<get_string_length( _binary_string ) / 2; i++ ) { char _temp_char; _temp_char = _binary_string[ i ]; _binary_string[ i ] = _binary_string[ ( get_string_length( _binary_string ) - 1 ) - i ]; _binary_string[ ( get_string_length( _binary_string ) - 1 ) - i ] = _temp_char; } _return_char = _binary_string; return _return_char; }
int main() { const int max_size = 100; int string_length = 0; char string[max_size]; char reverse_string[max_size]; printf("\nPlease enter input string: "); /* Note: we are not using gets, because gets is deprecated and can be dangerous. */ fgets(string, max_size, stdin); /* remove any new line from input string, if fgets has put '\n' at the end of string */ string_length = get_string_length(string); string[string_length] = 0; /* get the reversed string */ reverse(string, reverse_string); /* now compare */ if (!strcmp(string, reverse_string)) { printf("\nEntered string = %s, reversed string = %s." "\n%s = %s, hence %s is a palindrome.\n", string, reverse_string, string, reverse_string, string); } else { printf("\nEntered string = %s, reversed string = %s." "\n%s != %s, hence %s is not a palindrome.\n", string, reverse_string, string, reverse_string, string); } return 0; }
void win32_windowed_app::print(const char* string) { print_to_debug_output(string); if (_log_file != nullptr) { _log_file->write_bytes(string, get_string_length(string)); } }
void text_entry::copy_text_to_fit(const wchar_t* new_text) { auto new_length = get_string_length(new_text); if (new_length > _max_text_length) { TRACE("WARNING : text is too large for text_entry:{}", get_id()); } _text.assign(new_text, std::min(new_length, _max_text_length)); }
void win32_cli_app::handle_trace(const char* file_name, int line_number, bool add_newline, const char* message) { UNUSED_PARAMETER(file_name); UNUSED_PARAMETER(line_number); ::WriteConsoleA(_output_handle, message, get_string_length(message), nullptr, nullptr); ::WriteConsoleA(_output_handle, "\n", 1, nullptr, nullptr); print_to_debug_output(message); if (add_newline) { print_to_debug_output("\n"); } }
extern char* file_read_line(xString *const line , FILE* fp) { char *result = NULL; string_clear(line); if ( NULL == fp ) error(FATAL, "NULL file pointer"); else{ boolean re_readline; do { char *const pLastChar = get_string_value(line) + get_string_size (line) -2; fpos_t startOfLine; fgetpos (fp, &startOfLine); re_readline = FALSE; *pLastChar = '\0'; result = fgets (get_string_value(line), (int) get_string_size(line), fp); if (result == NULL) { if (! feof(fp)) error (FATAL | ERROR, "Failure on attempt to read file"); } else if (*pLastChar != '\0' && *pLastChar != '\n' && *pLastChar != '\r') { /* buffer overflow */ re_readline = string_auto_resize(line); if (re_readline) fsetpos (fp, &startOfLine); else error (FATAL | ERROR, "input line too big; out of memory"); } else { char* eol; line->length = strlen (line->buffer); /* canonicalize new line */ eol = get_string_value(line) + get_string_length(line) - 1; if (*eol == '\r') *eol = '\n'; else if (*(eol - 1) == '\r' && *eol == '\n') { *(eol - 1) = '\n'; *eol = '\0'; --line->length; } } }while(re_readline); } return result; }
node * create_node(char *text) { node *new_node = (node*) malloc (sizeof(node)); if(new_node != NULL) { stringcopy(new_node->text,text); new_node -> next = NULL; new_node -> prev = NULL; new_node -> text_length = get_string_length(text); } return new_node; }
/** * @brief function to reverse the given string. * @param[in] string the input string. * @param[out] rev_string the reversed string would be placed in this variable. * @return none. */ void reverse(const char *in_string, char *rev_string) { int i, j; unsigned int length; length = get_string_length(in_string); for (i = length-1, j = 0; i >= 0; --i, ++j) rev_string[j] = in_string[i]; /* mark the end of string */ rev_string[j] = 0; }
void test_log_msg( ) { int ret = 0; char *test_file_name = "test_log_msg.txt"; char *ident = "test_log_msg()"; /* {{{ Calculate lengths. */ int ident_length = get_string_length(ident); int msg_length = 13; int pid_length = snprintf(NULL, 0, "%d", getpid()); int expected_length = 18 + pid_length + 9 + ident_length + 2 + msg_length + 1; /* }}} */ /* {{{ Redirect the stdout. */ int stdout_dupfd = dup(1); FILE *temp_out = fopen(test_file_name, "w"); dup2(fileno(temp_out), 1); /* }}} */ /* Log the message in the file. */ ret = log_msg(LOG_LVL_DBG, LOG_FAC_STD, "test_log_msg()", "Hello %s %d", "World", 1); fflush(stdout); /* Flush output so it goes to our file. */ /* {{{ Restore stdout. */ fclose(temp_out); dup2(stdout_dupfd, 1); close(stdout_dupfd); /* }}} */ /* Test that the log_msg doesn't fail. */ CU_ASSERT(!ret); FILE *stdout_file = fopen(test_file_name, "r"); char *read_buffer = malloc((expected_length + 1) * sizeof(char)); /* Try to read the expected_length + 1 so we can check if more chars than * those expected are written. */ int read_length = fread(read_buffer, sizeof(char), expected_length + 1, stdout_file); free(read_buffer); fclose(stdout_file); unlink(test_file_name); /* Test that we only read the written bytes. */ CU_ASSERT(read_length == expected_length); }
void segment_and_get_base64_index( int _string_length, char _string[ _string_length ] ) { int i, j, k = 0; char _six_bit_array[ _string_length / 6 ][ 7 ]; int _base64_index_numbers[ _string_length / 6 ]; for( i=0; i<( _string_length / 6 ); i++ ) { j = 0; while( j<6 ) { _six_bit_array[ i ][ j ] = _string[ k ]; j = j + 1; k = k + 1; } _six_bit_array[ i ][ j ] = '\0'; } for( i=0; i<( _string_length / 6 ); i++ ) { _base64_index_numbers[ i ] = get_base64_index_value( _six_bit_array[ i ] ); } char _final_encoded_string[ ( _string_length / 6 ) ]; for( i=0; i<( _string_length / 6 ); i++ ) { _final_encoded_string[ i ] = base64_index_table[ _base64_index_numbers[ i ] ]; } _final_encoded_string[ ( _string_length / 6 ) ] = '\0'; if( RAW_DATA.APPEND_NEEDED == 1 ) { for( i=1; i<=RAW_DATA.APPEND_COUNT; i++ ) { _final_encoded_string[ get_string_length( _final_encoded_string ) - i ] = '='; } } fprintf( stdout, "\nEncoded string-------------------------------\n\n%s\n", _final_encoded_string ); }
xString* __file_get_line() { xString *result = NULL; int c; if (g_file.line == NULL) g_file.line = string_new(); string_clear (g_file.line); do { c = __file_get_ch(); if (c != EOF) string_set_char(g_file.line, c); if (c == '\n' || (c == EOF && get_string_length(g_file.line) > 0)) { set_string_terminate(g_file.line); result = g_file.line; break; } } while (c != EOF); return result; }
static void window_text_input_paint(){ rct_window *w; rct_drawpixelinfo *dpi; window_paint_get_registers(w, dpi); window_draw_widgets(w, dpi); int y = w->y + 25; int no_lines = 0; int font_height = 0; gfx_draw_string_centred(dpi, input_text_description, w->x + WW / 2, y, w->colours[1], &TextInputDescriptionArgs); y += 25; RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16) = 224; RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_FLAGS, uint16) = 0; char wrapped_string[512]; strcpy(wrapped_string, text_input); // String length needs to add 12 either side of box // +13 for cursor when max length. gfx_wrap_string(wrapped_string, WW - (24 + 13), &no_lines, &font_height); gfx_fill_rect_inset(dpi, w->x + 10, y, w->x + WW - 10, y + 10 * (no_lines + 1) + 3, w->colours[1], 0x60); y += 1; char* wrap_pointer = wrapped_string; int char_count = 0; uint8 cur_drawn = 0; for (int line = 0; line <= no_lines; ++line){ gfx_draw_string(dpi, wrap_pointer, w->colours[1], w->x + 12, y); int string_length = get_string_length(wrap_pointer); if (!cur_drawn && (gTextInputCursorPosition <= char_count + string_length)){ // Make a copy of the string for measuring the width. char temp_string[512] = { 0 }; memcpy(temp_string, wrap_pointer, gTextInputCursorPosition - char_count); int cur_x = w->x + 13 + gfx_get_string_width(temp_string); int width = 6; if ((uint32)gTextInputCursorPosition < strlen(text_input)){ // Make a new 1 character wide string for measuring the width // of the character that the cursor is under. temp_string[1] = '\0'; temp_string[0] = text_input[gTextInputCursorPosition]; width = max(gfx_get_string_width(temp_string) - 2, 4); } if (w->frame_no > 15){ uint8 colour = RCT2_ADDRESS(0x0141FC48, uint8)[w->colours[1] * 8]; gfx_fill_rect(dpi, cur_x, y + 9, cur_x + width, y + 9, colour + 5); } cur_drawn++; } wrap_pointer += string_length + 1; if (text_input[char_count + string_length] == ' ')char_count++; char_count += string_length; y += 10; } }