![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 | |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Quote:
|
|
|
|
|
|
|
#12 |
|
Programming Guru
![]() ![]() ![]() |
I still favor my find_first_of approach(), regarding the symbols... its flexible, also could be used for digits and alphas (although that'd be overkill since isdigit and isalpha is available).
![]() Regarding my above isSymbol function, it would be as easy as: if (isSymbol(myChar)) symbolCount++;
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#13 | |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Quote:
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
|
#14 |
|
Programming Guru
![]() ![]() ![]() |
You showed sufficient effort, and I became bored... try something like this:
#include <iostream>
#include <string>
#include <cctype>
#include <conio.h>
using namespace std;
bool isSymbol (char x);
void ParseInput (string input);
// counters
int alpha = 0, digit = 0, symbol = 0;
int main (void)
{
char myInput[250];
cout << "Enter characters: " << endl;
cin.getline(myInput, 250);
cout << myInput << endl;
ParseInput (myInput);
cout << "Digits: " << digit << endl;
cout << "Alpha: " << alpha << endl;
cout << "Symbols: " << symbol << endl;
system("PAUSE");
return 0;
}
void ParseInput (string input)
{
int i = 0;
for (i = 0; i < input.length(); i++)
{
if ( isalpha(input.at(i)) )
alpha++;
else if ( isdigit(input.at(i)) )
digit++;
else if ( isSymbol(input.at(i)) )
symbol++;
}
}
bool isSymbol (char x)
{
string SYMBOLS = "X ~`!@#$%^&*()_+-={}[]:\";'<>?,./|";
bool result = false;
int location = 0;
location = SYMBOLS.find_first_of(x);
if (location > 0)
result = true;
return result;
}
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#15 |
|
Newbie
Join Date: Mar 2006
Posts: 19
Rep Power: 0
![]() |
thank you very much! i appreciate it
|
|
|
|
|
|
#16 |
|
Programming Guru
![]() ![]() ![]() |
You're welcome.
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|