Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to center a word on the screen?

Status
Not open for further replies.

Patgal

Technical User
Nov 22, 2002
1
US
Hi. I'm a new member here. My instructor gave me a program to write. We have to read a string from the keyboard and display those words on the screen one word per line starting with the shortest word first. As each word is dispalyed, we have to center the word on the screen. for example, if the string is "mathew is good." then we have to display it like:-
is
good.
mathew

Now, I've already put the string into an array. I find for space(20h) and write the number of characters. Like this:- mathew6is2good.5

Now, I have to find the smallest number and write that number of character before it. I have no idea how to do it. and also i don't know how to center the word on the screen. I would really appreciate if anyone could give me a helping hand. Thank you.

 
You prolly shouldn't have put it as matthew6is2good.5, unless you have an array somewhere that tells you where each word ends and/or starts... so how would YOU know where each word ends or starts?

To center a string:
NumSpaces = (ScreenWidth - StringSize)/2

Where NumSpaces is the number of spaces you put before the string.

"Information has a tendency to be free. Which means someone will always tell you something you don't want to know."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top