Click here to Skip to main content
16,011,436 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: VirtualAlloc v/s new Pin
Joe Woodbury19-Dec-02 6:44
professionalJoe Woodbury19-Dec-02 6:44 
GeneralRe: VirtualAlloc v/s new Pin
Tim Smith19-Dec-02 5:59
Tim Smith19-Dec-02 5:59 
GeneralRe: VirtualAlloc v/s new Pin
Alvaro Mendez19-Dec-02 6:18
Alvaro Mendez19-Dec-02 6:18 
QuestionHow to get CPU usage by PDH? Pin
Dudi Avramov19-Dec-02 5:15
Dudi Avramov19-Dec-02 5:15 
GeneralConvert string --> INT or FLOAT with ERROR checking! Pin
Daniel Strigl19-Dec-02 5:07
Daniel Strigl19-Dec-02 5:07 
GeneralRe: Convert string --> INT or FLOAT with ERROR checking! Pin
Tim Smith19-Dec-02 5:13
Tim Smith19-Dec-02 5:13 
GeneralRe: Convert string --> INT or FLOAT with ERROR checking! Pin
Daniel Strigl19-Dec-02 20:28
Daniel Strigl19-Dec-02 20:28 
GeneralRe: Convert string --> INT or FLOAT with ERROR checking! Pin
Alvaro Mendez19-Dec-02 9:31
Alvaro Mendez19-Dec-02 9:31 
Here's some old code of mine that checks if a string value is numeric according to how you need it. For example, if you don't want it to be negative, you pass the Unsigned flag; if it can have a decimal point, you pass it the Decimal flag; etc. Notice that it assumes that a decimal point is a dot.


enum NumericFlag
{
	Unsigned,		// can only be positive and non-decimal
	Signed,		// can be positive or negative
	Decimal,		// can be positive and have a decimal point
	SignedDecimal	// can be positive or negative and have a decimal point
};
 
// Returns true if self is a valid number based on the given flag.
bool IsNumeric(const char* szValue, NumericFlag flag /*= Unsigned*/) const
{
	assert(szValue);
	int nLen = strlen(szValue);
 
	// Check every character individually
	for (int iPos = 0, nDecimalPos = -1; iPos < nLen; iPos++)
	{
		char c = szValue[iPos];
 
		// Check for a digit
		if (isdigit(c))
			continue;
 
		// Check for a negative sign
		if (c == '-' && iPos == 0 && (flag & Signed))
			continue;
 
		// Check for a decimal point
		if (c == '.' && nDecimalPos < 0 && (flag & Decimal))
		{
			nDecimalPos = iPos;
			continue;
		}
 
		return false;
	}
 
	return !!nLen;  // if it's empty, it's not a valid number
}


Regards,
Alvaro


Well done is better than well said. -- Benjamin Franklin
(I actually prefer medium-well.)
GeneralRe: Convert string --> INT or FLOAT with ERROR checking! Pin
Daniel Strigl19-Dec-02 20:29
Daniel Strigl19-Dec-02 20:29 
GeneralRe: Convert string --> INT or FLOAT with ERROR checking! Pin
Jörgen Sigvardsson19-Dec-02 13:28
Jörgen Sigvardsson19-Dec-02 13:28 
GeneralRe: Convert string --> INT or FLOAT with ERROR checking! Pin
Daniel Strigl19-Dec-02 20:28
Daniel Strigl19-Dec-02 20:28 
GeneralGEtTextExtentExPoint font escapement = 900 Pin
Braulio Dez19-Dec-02 4:51
Braulio Dez19-Dec-02 4:51 
GeneralRe: GEtTextExtentExPoint font escapement = 900 Pin
Alvaro Mendez19-Dec-02 11:18
Alvaro Mendez19-Dec-02 11:18 
GeneralFactorial Pin
liboogie1919-Dec-02 4:49
liboogie1919-Dec-02 4:49 
GeneralRe: Factorial Pin
AlexO19-Dec-02 4:57
AlexO19-Dec-02 4:57 
GeneralRe: Factorial Pin
Peter Weyzen19-Dec-02 9:19
Peter Weyzen19-Dec-02 9:19 
GeneralRe: Factorial Pin
Anonymous19-Dec-02 9:58
Anonymous19-Dec-02 9:58 
GeneralProgramming problem Pin
Anonymous19-Dec-02 3:38
Anonymous19-Dec-02 3:38 
GeneralRe: Programming problem Pin
Maximilien19-Dec-02 3:50
Maximilien19-Dec-02 3:50 
GeneralRe: Programming problem Pin
Anonymous19-Dec-02 3:59
Anonymous19-Dec-02 3:59 
GeneralRe: Programming problem Pin
AlexO19-Dec-02 4:52
AlexO19-Dec-02 4:52 
GeneralRe: Programming problem Pin
Michael P Butler19-Dec-02 3:53
Michael P Butler19-Dec-02 3:53 
GeneralRe: Programming problem Pin
Rage19-Dec-02 3:54
professionalRage19-Dec-02 3:54 
GeneralRe: Programming problem Pin
Joe Woodbury19-Dec-02 5:18
professionalJoe Woodbury19-Dec-02 5:18 
GeneralRe: Programming problem Pin
Anonymous19-Dec-02 5:33
Anonymous19-Dec-02 5:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.