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?
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.
Like at ms office.. and like this left tag. 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.
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.
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? - Obtain line of text from the user.
- Strip trailing whitespace from the text.
- Repeat:
- ... Split the text at the beginning of the last whitespace sequence before the 60th character.
- ... Output the text preceding the split.
- ... Strip leading whitespace from text following the split.
- ... Text = the text following the split.
- 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)?
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.
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.
-
#include <iostream>
-
#include <cstring>
-
using namespace std;
-
int main()
-
-
{
-
char original[500],output[61],word[61];
-
-
cout << "Give someting: ";
-
cin >> original;
-
-
int word_pos=0, original_pos=0;
-
-
while(1)
-
{
-
while ((original[original_pos] == ' ') && (original[original_pos] == '\n') && (original[original_pos] == '\t') && (original[original_pos] == '\0'))
-
{
-
original_pos++;
-
}
-
-
if (original[original_pos] == '\0')
-
{
-
cout << output << endl;
-
return 0;
-
}
-
-
while ((original[original_pos] != ' ') && (original[original_pos] != '\n') && (original[original_pos] != '\t') && (original[original_pos] != '\0'))
-
{
-
word[word_pos] = original[original_pos];
-
word_pos++;
-
original_pos++;
-
}
-
-
-
-
if ((word_pos + strlen(output)) > 60)
-
{
-
word[word_pos] = '\0';
-
cout << output << endl;
-
strcpy(output,word);
-
word_pos=0;
-
}
-
else
-
{
-
word[word_pos] = ' ';
-
word_pos++;
-
word[word_pos] = '\0';
-
strcat(output,word);
-
word_pos=0;
-
}
-
if (original[original_pos] == '\0')
-
{
-
//cout << output << endl;
-
return 0;
-
}
-
}
-
return 0;
-
}
As we talk, I wrote this and couldn't find where is my mistake.
donbock 2,426
Recognized Expert Top Contributor
Please explain what is going wrong with that code. It helps to know the symptoms.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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>
|
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
|
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...
|
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
|
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...
| |
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...
|
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
|
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"...
|
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
|
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>
|
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...
| |
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,...
|
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...
|
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |