| | |
Edit1->Text (Iterate over text -Rather Urgent
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2007
Posts: 6
Reputation:
Solved Threads: 0
The task is to put text in ab Edit box & then to iterate over it. The result should be in a block graph. If there is a vowel =="A" then block one should rise, if =="B" then block two should rise to represent it.
I can make this work for the first letter in the edit box with the following code:
BUT this only works when the letter is at Index=1. I need to scan a sentence so that the result of the graph shows how many A's how many E's how many I's how many O's how many U's.
How do I get it to read over the text & not just the first letter?
I can make this work for the first letter in the edit box with the following code:
C++ Syntax (Toggle Plain Text)
/* { int Index; Index=1; for(Index=1;Index<=5;Index++) { if(Edit1->Text=="A") { Shape1->Height= (Shape1->Height+5); Shape1->Top = Shape1->Top -5; } if(Edit1->Text=="E") { Shape2->Height= (Shape2->Height+5); Shape2->Top = Shape2->Top -5; } if(Edit1->Text=="I") { Shape3->Height= (Shape3->Height+5); Shape3->Top = Shape3->Top -5; } if(Edit1->Text=="O") { Shape4->Height= (Shape4->Height+5); Shape4->Top = Shape4->Top -5; } if(Edit1->Text=="U") { Shape5->Height= (Shape5->Height+5); Shape5->Top = Shape5->Top -5; } }*/
How do I get it to read over the text & not just the first letter?
Last edited by Ancient Dragon; Jul 26th, 2007 at 2:21 pm. Reason: add code tags
•
•
Join Date: Jul 2005
Posts: 1,735
Reputation:
Solved Threads: 281
Presumably Edit1->Text is a string of some type. Assuming this is a Windows based program, then it's probably a C style string. If that assumption is correct then each letter in the string can be accessed by using the [] operator, like this:
Edit1->Text[x];
where x ranges from 0 to strlen(Edit1->Text) - 1.
If Edit1->Text is some form of a string other than a C style string, then some other form of access may be necessary.
NB: you might need to copy Edit1->Text to another string like this:
char input[256];
strcpy(input, Edit1->Text);
and then iterate through input if this
Edit1->Text[x];
doesn't work.
Edit1->Text[x];
where x ranges from 0 to strlen(Edit1->Text) - 1.
If Edit1->Text is some form of a string other than a C style string, then some other form of access may be necessary.
NB: you might need to copy Edit1->Text to another string like this:
char input[256];
strcpy(input, Edit1->Text);
and then iterate through input if this
Edit1->Text[x];
doesn't work.
Last edited by Lerner; Jul 26th, 2007 at 1:35 pm.
•
•
Join Date: May 2007
Posts: 6
Reputation:
Solved Threads: 0
Hi there,
Its C++, using Boreland 5 as a compiler, so its really visual C++, but using C++ as basis. I'm afraid this didn't work, do you have any other ideas.
The problem is just to iterate over a line of text & then show the vowels in a bar chart.
Any suggestions would be greatly appreciated.
Thanks
jenco
Its C++, using Boreland 5 as a compiler, so its really visual C++, but using C++ as basis. I'm afraid this didn't work, do you have any other ideas.
The problem is just to iterate over a line of text & then show the vowels in a bar chart.
Any suggestions would be greatly appreciated.
Thanks
jenco
•
•
•
•
Presumably Edit1->Text is a string of some type. Assuming this is a Windows based program, then it's probably a C style string. If that assumption is correct then each letter in the string can be accessed by using the [] operator, like this:
Edit1->Text[x];
where x ranges from 0 to strlen(Edit1->Text) - 1.
If Edit1->Text is some form of a string other than a C style string, then some other form of access may be necessary.
NB: you might need to copy Edit1->Text to another string like this:
char input[256];
strcpy(input, Edit1->Text);
and then iterate through input if this
Edit1->Text[x];
doesn't work.
•
•
Join Date: Jul 2005
Posts: 1,735
Reputation:
Solved Threads: 281
Edit->Text should be a word or a phrase, say you entered ther phrase--three blind mice. Again that word/phrase should be a string of some type, in Borland it might be called a TString or some such. Whatever. That string type should have an overloaded [] operator associated with it to allow you to access each letter in the word or phrase (and it should have a method for you to extract the embedded C style string if you wish, maybe c_str() or some such, if you really wanted to). With that you can iterate over each letter in the input one by one. When refering to a hard coded letter in C/C++ you use single quotes, like this, 'A', rather than double quotes like this, "A", which are used to denote a string called a literal string (it isn't quite the same thing as a routine C style string, but it's close). Therefore, I'd:
1) Find the length of the string in Edit1 using whatever method you have available.
2) Convert the string into all caps or all lower case letters so I didn't have to worry about 'A' vs 'a', etc.
3) Create a container to hold the number of A, E, I, O and Us found in the string
4) Iterate over the entire string incrementing the appropriate counter in the container based on the letter found.
5) Display the results graphically by iterating over the container of counters representing the number of A, E, I, O and Us.
So maybe something like this:
I don't like the idea of having to learn the basic principles of looping, usage of the [] operator to access individual char of a string, and retrieval of and manipulation of data from edit boxes in addition and creation of colored bars to display results. But if that's what you have to do, then so be it.
1) Find the length of the string in Edit1 using whatever method you have available.
2) Convert the string into all caps or all lower case letters so I didn't have to worry about 'A' vs 'a', etc.
3) Create a container to hold the number of A, E, I, O and Us found in the string
4) Iterate over the entire string incrementing the appropriate counter in the container based on the letter found.
5) Display the results graphically by iterating over the container of counters representing the number of A, E, I, O and Us.
So maybe something like this:
C++ Syntax (Toggle Plain Text)
//copy TString or whatever into a C style string char input[256]; strcpy(input, Edit1->Text.c_str()); //find it's length int len = strlen(input); //convert it to all upper case letters for(int j = 0; j < len; ++j) input[j] = toupper(input[j]); //declare container of counters and initialize to zero int counters[5] = 0; //iterate over input finding vowels for(int j = 0; j < len; ++j) { //I'd use a switch statement instead of a series of if statements switch(input[j]) { case 'A': //notice single quotes, not double counter[0]++; break; case 'E': counter[1]++; break; //etc } } //use a loop and the graphical interface to create pretty bars representing number of A, E, I, O and Us found in input which in turn was Edit1->Text.
I don't like the idea of having to learn the basic principles of looping, usage of the [] operator to access individual char of a string, and retrieval of and manipulation of data from edit boxes in addition and creation of colored bars to display results. But if that's what you have to do, then so be it.
Last edited by Lerner; Jul 26th, 2007 at 6:11 pm.
![]() |
Similar Threads
- Cant readline in text file.... URGENT help~ (VB.NET)
- code illiterate - add text from 5 TEdit to 1 (Pascal and Delphi)
- problem with convert jumbled text file to unjumbled text file (C)
- text to numbers, numbers to texrt (Visual Basic 4 / 5 / 6)
- Text Filters (OS X)
Other Threads in the C++ Forum
- Previous Thread: C++ Help please with passing arrays
- Next Thread: Is there a C++ doctor in the house?
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll download dynamic encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib library linkedlist linker linux loop looping loops map math matrix memory microsoft newbie news number output parameter pointer problem program programming project proxy python random read recursion recursive reference return string strings struct studio system template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






