Try sprintf! chunk a string output buffer ... If you want to center align some text using the printf or sprintf functions, you can just use the following:
function center_text($word){
$tot_width = 30;
$symbol = "-";
$middle = round($tot_width/2);
$length_word = strlen($word);
$middle_word = round($length_word / 2);
$last_position = $middle + $middle_word;
$number_of_spaces = $middle - $middle_word;
$result = sprintf("%'{$symbol}{$last_position}s", $word);
for ($i = 0; $i %26lt; $number_of_spaces; $i++){
$result .= "$symbol";
}
return $result;
}
$string = "This is some text";
print center_text($string);
off course you can modify the function to use more arguments.
Is there any function in c++ to center align output text ?
there should not be but you can make one method.
Reply:try graphics in c++....
u can find the examples frm graphics.h header file
use "outtextxy(x,y,"output"); function
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment