A
ATH0
How to search for special character { } and how to count them..
I got field called text ( undefined length ) and in this field you must
define "{" as start and "}" as end of some text line. If you can find both
{} then you have to count them.
example:
bla bla bla {bla { asd asd}
Result:
Words : 7
{ signs : 2
closed braces: 1
How can i make this?
--------------------------------------------------------------------
#include <iostream.h>
#include <string.h>
int letter=0;
int word=0;
int openBrace=0;
int closedBrace=0;
int completBrace=0;
char textLine[255]; // omited length
void main()
{
cout << "\n";
cout <<"Enter text line: ";
cin.getline(texLine,255);
_strupr(textLine);
for (int i=0; i<strlen(textLine); i++)
{
if (textLine != ' ')
word++;
if (textLine == '{') // special character
openBrace++;
if (textLine == '}') // special character
closedBrace++;
if (textLine == '{' || textLine == '}') //
special character
completBrace++;
if (textLine == ' ')
word++;
}
word++; // for empty places
cout <<"# of words: " <<word<<endl;
cout <<"# of open braces: "<<openBrace<<endl;
cout <<"# closed braces: " <<closedBraces<<endl;
cout <<"# compleated braces: "<<completBrace<<endl;
cout << "\n";
}
I got field called text ( undefined length ) and in this field you must
define "{" as start and "}" as end of some text line. If you can find both
{} then you have to count them.
example:
bla bla bla {bla { asd asd}
Result:
Words : 7
{ signs : 2
closed braces: 1
How can i make this?
--------------------------------------------------------------------
#include <iostream.h>
#include <string.h>
int letter=0;
int word=0;
int openBrace=0;
int closedBrace=0;
int completBrace=0;
char textLine[255]; // omited length
void main()
{
cout << "\n";
cout <<"Enter text line: ";
cin.getline(texLine,255);
_strupr(textLine);
for (int i=0; i<strlen(textLine); i++)
{
if (textLine != ' ')
word++;
if (textLine == '{') // special character
openBrace++;
if (textLine == '}') // special character
closedBrace++;
if (textLine == '{' || textLine == '}') //
special character
completBrace++;
if (textLine == ' ')
word++;
}
word++; // for empty places
cout <<"# of words: " <<word<<endl;
cout <<"# of open braces: "<<openBrace<<endl;
cout <<"# closed braces: " <<closedBraces<<endl;
cout <<"# compleated braces: "<<completBrace<<endl;
cout << "\n";
}