Anyone have a good algorithm for centering text in a framed greeting?
Anyone have a good algorithm for centering text in a framed greeting?
Using:
vector<string> greeting;
and
string line;
and
greeting.push_back(line);
for example
see Accelerated C++ section 2.5.4 The complete framing program.
Code:void PrintCenteredText(char* String) { for(int i = 0; i < ((80 - strlen(String)) / 2); i++) cout << " "; cout << String; }
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
Centering text is easy... using 'gotoxy' (assuming you mean DOS/console):Code:centeredX = (SCREEN_WIDTH-strlen(TEXT_TO_BE_CENTERED))/2; centeredY = (SCREEN_HEIGHT)/2; gotoxy(centeredX, centeredY);
stupid login!
I dont get it.. I'm using Dev-C++.. this is my code:
And this is the compiling stats:Code:#include <iostream> #include <stdlib.h> #include <conio.h> int main() { gotoxy(10,10); printf("Hello World"); return 0; }
Building Makefile: "E:\Dev-C++\Projects\Temp\Makefile.win"
Executing make...
make.exe all -f "E:\Dev-C++\Projects\Temp\Makefile.win"
g++.exe -c main.cpp -o main.o -I"E:\DEV-C++\include" -I"E:\DEV-C++\include" -s
main.cpp: In function `int main()':
main.cpp:7: `gotoxy' undeclared (first use this function)
main.cpp:7: (Each undeclared identifier is reported only once for each function
it appears in.)
g++.exe main.o -o "temp.exe" -L"E:\DEV-C++\lib" -I"E:\DEV-C++\include" -I"E:\DEV-C++\include" -s
Execution terminated
Please Help
what does signature stand for?
Muahhahha, gotoxy, the non-standard function in conio.h
Read the tutorials to find out how to make your own gotoxy
Anyway.. this doesnt work either: SetConsoleCursorPosition .. unless I don't know how to make it.. plz help (short-examples/tutorials)
what does signature stand for?
SetConsoleCursorPosition is a windows function... you need to #include <windows.h>
Code:#include <windows.h> ... void WinConsole_gotoxy(int x, int y) { COORD coord = {x, y}; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord); }
You didn't phrase you question clear. It could meanIt is a nation born in the quiet part of the mind,
that has no fantasy of omnipotence,
no God but nature, no net of one vow,
no dark corner of the poor, no fugue-work of hate,
no hierarchies of strength, knowledge, or love,
no impure water spasming from rock, no swarm of polluted flies,
no ash-heap of concrete, gypsum, and glass,
no false mercy or truths buried in excrement;
and in this nation of men and women,
no face in the mirror reflecting more darkness
than light, more strife than love, no more strife
than in my hands now, as I sit on a rock,
tearing up bread for red and white carp
pushing out of their element into mine.
take this poem as
a string of charecters and try to center it so that
there's about a 5 charecter margin on both size and your
line is 60 charecters. Of course this isn't clear either.
*looks at the date of the original post*
WTF?
hopefully it didn't take the original poster 4 days to come
up with a solution.
Thanks.. I got it now.. another thing, how'd I set a text's foreground colour?Originally posted by BMJ
SetConsoleCursorPosition is a windows function... you need to #include <windows.h>
Code:#include <windows.h> ... void WinConsole_gotoxy(int x, int y) { COORD coord = {x, y}; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord); }
what does signature stand for?