Bench's Profile User Rating: *****

Reputation: 859 Master
Active Posts:
2,343 (0.76 per day)
20-August 07
Profile Views:
Last Active:
User is offline Nov 02 2014 06:36 AM

Previous Fields

OS Preference:
Who Cares
Favorite Browser:
Who Cares
Favorite Processor:
Who Cares
Favorite Gaming Platform:
Who Cares
Your Car:
Who Cares
Dream Kudos:
Expert In:

Latest Visitors

Icon   Bench has not set their status

Posts I've Made

  1. In Topic: Functions Code bring up strange results

    Posted 22 Oct 2014

    View PostRemington_Andrews, on 22 October 2014 - 10:14 PM, said:

    float get_input()
    	int num1;
    	printf("Enter a Real Number Greater than 0:  \n");
    	scanf_s("%d", &num1);
    	while (num1 < 0)
    		printf("Invalid Number, try again \n");
    		scanf_s("%d", &num1);
    	return num1;
    Are you trying to use floating-point numbers or integers? Your program seems to be somewhat confused where you read an int but return a float, and pass floating-point numbers around elsewhere. Which are you really expecting to use?

    More information on scanf here - http://en.cppreferen...m/w/c/io/fscanf
  2. In Topic: Logical XOR in C++

    Posted 17 Oct 2014

    View Postsbesch, on 16 October 2014 - 09:54 PM, said:

    I don't want to sound like a trouble maker on my first post, but I'm afraid you are all wrong in essence. To wit, unless you want to depend on compiler implementation and good user behavior, I would not suggest using any of the solutions given without qualification.
    My initial reply to this thread is not in any way dependent on compiler implementation, it depends upon the fact that there is a logical equivalence between 'XOR' and (!(x&&y)) && (x||y).

    This is a mathematical truth, so it's actually impossible for that logic to fail, unless your compiler is completely broken.

    View Postsbesch, on 16 October 2014 - 09:54 PM, said:

    Even if you assume that all compilers on earth use the same standard values for true and false, I can pretty much guarantee that there will be some nutty user somewhere who will typecast and int to a boolean, then pass in all manner of non-zero values which when XOR'd will give non-zero results. In truth, the only guaranteed way to make this work is by writing an XOR function:
    bool XOR (bool a, bool b ){
     int ba=a?1:0;
     int bb=b?1:0;
     return ((ba ^ bb)==0);
    That essentially performs the same logic as the function in my original reply by forcing the integer representation to one or zero. The disadvantage to your example 'in the real world', is that calling code may suffer warnings for types which do not implicitly cast to bool, such as void*.

    View Postsbesch, on 16 October 2014 - 09:54 PM, said:

    This still assumes that FALSE is zero, but I'm a lot more comfortable with that assumption than I am with the assumption that TRUE will always be the same positive value (such as 1). I agree that this is a pain. I agree that C++ should include this operator both for type safety and for cross compiler consistency. But it doesn't. Ah well
    There is no need to "assume" that false is a zero value because the ISO C++ standard provides an absolute cast-iron guarantee that false will always evaluate to zero for a standard-conforming C++ compiler.
  3. In Topic: Is there a better way to parse & format phone numbers?

    Posted 4 Sep 2014

    RegEx is specifically intended for pattern matching - so it's a very appropriate tool for parsing data such as phone numbers.

    In general, there's never an absolutely right/wrong way to create working code; although the preferred solutions are nearly always the simplest ones, and the ones which clearly show your intent at the time of writing it (i.e. intent to solve a particular problem - code which is expressive enough that its rationale is clear to anyone else reading - or yourself in 6 months time).

    While RegEx syntax can very easily become cryptic (some people avoid it for this reason), and 'how-it-works' is not always clear (especially not to those who don't use RegEx very often), the intent of code which uses RegEx pattern matching is often a lot more obvious, even if the pattern itself is hard-to-grok by casually glancing over it. RegEx itself is usually a lot more powerful and flexible for parsing nontrivial string formats too.

    As an example - the string 1-888-8888 could be matched with a pattern \d-\d{3}-\d{4} (You can validate the RegEx itself with any regex tool - e.g. ) - with a little tinkering, you could extend that pattern to match different ways of expressing phone numbers.

    There's some decent example code for std::regex here (assuming you're using a recent C++11 compiler) -

    It's also 'OK' to do things with a whole bunch of nested conditional/loops as well, but you need to consider how easy it is for code like that to get out-of-control - just a few special cases "over here" can lead to a few more hacks and special cases "over there" (particularly when you're dealing with magic numbers and fixed positions within a sequence); and you can easily end up with a couple of loops/If statements turning into a multi-headed hydra with dozens of paths and probably code which may be less flexible and whose intent is murky.

My Information

Member Title:
D.I.C Lover
33 years old
August 15, 1982
Years Programming:
Programming Languages:
C, C++, C#

Contact Information

Website URL:
Website URL  http://


Page 1 of 1
  1. Photo

    Sy-Coderz Icon

    23 Jun 2012 - 09:47
    bro please add me at : [email protected]
    add me please i need some help
    i wait u
  2. Photo

    OLH064 Icon

    28 Aug 2011 - 11:09
    That is the best signature ever.
  3. Photo

    Jeff H Icon

    19 Jun 2011 - 00:54
    Hey Bench,
    I have dual monitors and was looking over at the other one as I was trying to give you a + rep and accidently hit the - rep.
    Just let me know what I need to do to help get it changed. I already left a reply in the thread.
  4. Photo

    Jeff H Icon

    19 Jun 2011 - 00:54
    Hey Bench,
    I have dual monitors and was looking over at the other one as I was trying to give you a + rep and accidently hit the - rep.
    Just let me know what I need to do to help get it changed. I already left a reply in the thread.
  5. Photo

    sleepybug Icon

    20 Feb 2010 - 06:45
    hey bench!!thanks for the simple code concerning node,pointer and linked list ,you after learning pointers i understand your that program much more clearly and its simple working..thanks for help buddy.
  6. Photo

    neptunusmaris Icon

    16 Feb 2010 - 10:56
  7. Photo

    CodingDesire Icon

    16 Feb 2010 - 09:21
    Hello there, thank you very much for your help!
Page 1 of 1