Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 8th, 2006, 10:35 AM   #11
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Quote:
Originally Posted by DaWei
Nah, there are all sorts of things, like 'ispunct', 'isgraph', on and on. See the <locale> header.
If he was looking for all punctuation, then that'd work, but he specifies five specific characters he's looking for.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old May 8th, 2006, 10:42 AM   #12
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,473
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is offline   Reply With Quote
Old May 8th, 2006, 10:45 AM   #13
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Quote:
(If you like, simply assume that, if a character is not a digit or puncuation, it is a letter. Also, just use the most common puncuation symbols (. , ? ! : ;)).
Guess that's interpretable a couple different ways. Anyway, I saw his list. He obviously needs to use the "isWinkyEmoticon" function.
__________________
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
DaWei is offline   Reply With Quote
Old May 8th, 2006, 11:11 AM   #14
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,473
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is offline   Reply With Quote
Old May 10th, 2006, 8:05 AM   #15
lilmul123
Newbie
 
Join Date: Mar 2006
Posts: 22
Rep Power: 0 lilmul123 is on a distinguished road
thank you very much! i appreciate it
lilmul123 is offline   Reply With Quote
Old May 10th, 2006, 9:31 AM   #16
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,473
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
You're welcome.
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:47 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC