Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* text_line_string()
- * Generate and return a string, as above, with text centered.
- */
- char* text_line_string(char *text, int length, char first, char second) {
- int text_length, text_print_length, pre_length;
- int i = 0, j = 0;
- static char buf[MAX_STRING_LENGTH]; /* Note - static! */
- text_length = strlen(text);
- text_print_length = count_non_protocol_chars(text);
- pre_length = (length - (text_print_length))/2; /* (length - (text length + '[ ]'))/2 */
- // pre_length = (length - (text_length + 4))/2; /* (length - (text length + '[ ]'))/2 */
- // pre_length = 2;
- while (i < pre_length) {
- if((i % 2) == 0)
- buf[i] = first;
- else
- buf[i] = second;
- i++;
- }
- // buf[i++] = '[';
- // buf[i++] = ' ';
- while (j < text_length)
- buf[i++] = text[j++];
- // buf[i++] = ' ';
- // buf[i++] = ']';
- while (i < length + (text_length - text_print_length)) /* Have to include the non printables */
- if((i % 2) == 0)
- buf[i++] = first;
- else
- buf[i++] = second;
- buf[i++] = '\r';
- buf[i++] = '\n';
- buf[i] = '\0'; /* Terminate the string. */
- return buf;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement