473,651 Members | 2,635 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can i align the input text to the left?

11 New Member
i want to write a program that input a text from user and align it to the left. Is there any command that i can use? How should i think?
Mar 20 '12 #1
12 5037
donbock
2,426 Recognized Expert Top Contributor
What do you mean by "align it to the left"?
  • Remove leading whitespace.
  • Print out a left-aligned copy of the input text.
  • Store a left-aligned copy of the input text in a character array. In a string. In a vector.
  • Something else.
Mar 20 '12 #2
logantr
11 New Member
Like at ms office..
and like this left tag.
Mar 20 '12 #3
donbock
2,426 Recognized Expert Top Contributor
I'm afraid I don't understand. Please post an example showing both the input text and the resultant left-aligned output text.
Mar 20 '12 #4
logantr
11 New Member
I couldn't tell. If a word at the end of line exceeds the column, shift it to the next line without dividing it. And every column should be 60 characters.
Mar 20 '12 #5
donbock
2,426 Recognized Expert Top Contributor
I would have called this "wrap text" rather than "align to the left".

Does this sound like what you want to do?
  1. Obtain line of text from the user.
  2. Strip trailing whitespace from the text.
  3. Repeat:
  4. ... Split the text at the beginning of the last whitespace sequence before the 60th character.
  5. ... Output the text preceding the split.
  6. ... Strip leading whitespace from text following the split.
  7. ... Text = the text following the split.
  8. Until (all text has been outputed).

Even if that sounds right, you still need to make some decisions:
  • How do you want to handle newlines or carraige returns embbed within the text?
  • How do you want to handle tab characters embedded within the text?
  • Do you want to handle whitespace at line breaks the way I suggest above (that is, throw it away)?
Mar 20 '12 #6
logantr
11 New Member
I understood what you mean and i will write it, except '... Split the text at the beginning of the last whitespace sequence before the 60th character.' i should try, because i ve some problems in this algoritms. You gave me an general idea that i need(want). Thanks donbock.
Mar 20 '12 #7
donbock
2,426 Recognized Expert Top Contributor
Another special case you need to think about: what do you want to do when there is a sequence of more than 60 non-whitespace characters? (That is, when it is impossible to break the line at a word boundary because you have a single word that is longer than the line limit.)

The logic I suggested earlier assumed that you want to preserve all leading whitespace. I should instead have invited you to decide what you want to do.
Mar 20 '12 #8
logantr
11 New Member
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4. int main()
  5.  
  6. {
  7.     char original[500],output[61],word[61];
  8.  
  9.     cout << "Give someting: ";
  10.     cin >> original;
  11.  
  12.     int word_pos=0, original_pos=0;
  13.  
  14.     while(1)
  15.     {
  16.         while ((original[original_pos] == ' ') && (original[original_pos] == '\n') && (original[original_pos] == '\t') && (original[original_pos] == '\0'))
  17.         {
  18.             original_pos++;
  19.         }
  20.  
  21.         if (original[original_pos] == '\0')
  22.         {
  23.             cout << output << endl;
  24.             return 0;
  25.         }
  26.  
  27.         while ((original[original_pos] != ' ') && (original[original_pos] != '\n') && (original[original_pos] != '\t') && (original[original_pos] != '\0'))
  28.         {
  29.             word[word_pos] = original[original_pos];
  30.             word_pos++;
  31.             original_pos++;
  32.         }
  33.  
  34.  
  35.  
  36.         if ((word_pos + strlen(output)) > 60)
  37.         {
  38.             word[word_pos] = '\0';
  39.             cout << output << endl;
  40.             strcpy(output,word);
  41.             word_pos=0;
  42.         }
  43.         else
  44.         {
  45.             word[word_pos] = ' ';
  46.             word_pos++;
  47.             word[word_pos] = '\0';
  48.             strcat(output,word);
  49.             word_pos=0;
  50.         }
  51.         if (original[original_pos] == '\0')
  52.         {
  53.             //cout << output << endl;
  54.             return 0;
  55.         }
  56.     }
  57.     return 0;
  58. }
As we talk, I wrote this and couldn't find where is my mistake.
Mar 26 '12 #9
donbock
2,426 Recognized Expert Top Contributor
Please explain what is going wrong with that code. It helps to know the symptoms.
Mar 26 '12 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

4
2727
by: multimatum2 | last post by:
Hello, I need to enable/disable input text forms... But... I need to have the same style (color...) in both modes.. Could you help me ? Thanx a lot A small sample... <HTML><HEAD><TITLE></TITLE></HEAD>
1
1713
by: Raja Gopal | last post by:
Hi, Can anyone please tell me how do I align the text on a label or a link button so that it looks better. Thanks, Raja Gopal
3
4212
by: Ali | last post by:
I have 3 html input tex in my asp.net form. Two of them are calling javascript client side to calculate the differnce of two dates and put the result into the third input text. i haven't include runat=server in those input texts. it works fine with me and i get the result in the third input text. Now when i want to insert the 3 html input text values into my database among other web controls ... i found out that i can't see them unlike web...
2
2521
by: magix | last post by:
Hi, I'm using Access Database with ASP. There is one particular thing that I have issue with. My purpose is for user to update their own profile. Their existing profile information will be display in Edit Form format. The problem is if the field has space, the second word will not display, when I display in input text format. E.g if My first name "User_FirstName" in my table has entry, let say "David
3
3988
by: acecraig100 | last post by:
I am fairly new to Javascript. I have a form that users fill out to enter an animal to exhibit at a fair. Because we have no way of knowing, how many animals a user may enter, I created a table with a createElement function to add additional entries. The table has the first row of input text boxes already in it. You have to click a button to add another row. That seems to be working fine. How do I pull the information from the input boxes...
3
2861
by: kvnsmnsn | last post by:
I've written the following Javascript file that includes an input text field and an output text field, the latter of which is initialized to zero. Each time the user enters a number in the input field and hits the space bar, that number gets added to the value in the output field and then the input field gets set to the empty string. The user can enter as many numbers into the input field as s/he wants. The problem I have with this is...
2
1898
idsanjeev
by: idsanjeev | last post by:
hello how can retrive the input text after submit button pressed and report a error message. i wants to post topic and if any error message is occured then retrive the inputed text but it forget its <%@ Language=VBScript%> <%Option Explicit If Request.Cookies("userid") = "" Then Response.Redirect "login.asp" Else Dim R, page,vopenflg Dim vlaunchby,i,vcount
4
2252
by: backups2007 | last post by:
I want to be able to pass rows of queried data to rows of input text boxes. As the example below shows, I have come up with this incomplete solution. But this code only passes the data to the first row. I need to be able to pass it to all the rows. <input type="text" name="prod_id1"><input type="text" name="qty1"> <input type="text" name="prod_id2"><input type="text" name="qty2"> <input type="text" name="prod_id3"><input type="text"...
2
9941
by: ismailc | last post by:
Hi, I need help please! I want to vertical align the text within a text box. I can set the vertical align of the text box but not the text. My text box has a style property of: style ="height : 20px; border : 1px solid #CCCCCC;" but my text is to high on top in the text box
3
13274
by: happyse27 | last post by:
Hi All, I wanted to align the text box for user registration but the code just wont budge... Kindly advise what is wrong? Cheers... Andrew <HTML>
0
8347
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8792
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8571
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6157
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5605
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4280
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1905
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1585
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.