question for any C++ progammers

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Robert Ambrose
Date:  
Subject: question for any C++ progammers
This is more of a C than a C++ solution, but it'll work for C++ as well.
If you're just starting out, you're probably doing mostly C'ish stuff
anyway. (OTOH, maybe not, I've never taken a class on C or C++).

An easy way is to use the strtol() library function. If the conversion
stops on something other than a null char, it's not a valid numeric value.

It'll go something like this:

    char *endofbuf;
    value = strtol(buf, &endofbuf, 10);
    if(*endofbuf != '\0')
    {
        moan();
    }
    if(value < 0)
    {
        moan();
    }


rna

On Wed, 16 Aug 2000, Eric Samson wrote:

> Thanks everyone, I will give it a shot when I get home. I just thought that
> it was odd that it ran from the prompt one day and not the next. The book I
> am using was pretty vague on the compiler syntax. I compiled it without the
> .o extension as well, I was about to go out and purchase code warrior, so
> hopefully you guys just saved me some $$$ : )
>
> I am pretty new to C++, compiling, etc., I really want to learn this
> stuff... I am trying to figure out how to validate input from a user to
> make it accept only positive numeric values. I was using a while loop to
> check it, but when the user enters an alpha character, I get stuck in the
> loop of death, I am sure many of you have experienced this. I asked my
> instructor how to do this, but he said that he wasn't sure. would an if
> statement nested in a while loop solve my problem??
>
> Sorry about these newbie questions, but it's my second week in the class.. :
> )
>
>
> ----Original Message Follows----
> From: Robert Ambrose <>
> Reply-To:
> To:
> Subject: Re: question for any C++ progammers
> Date: Wed, 16 Aug 2000 07:39:50 -0700 (MST)
>
>
> First the .o extension is for compiled but not linked modules. Your
> command line should be something like 'g++ Assn2.cpp -oexp1', or more
> commonly: 'g++ Assn2.cpp -oAssn2'.
>
> You problem is probably the 'current directory' is not in your PATH. Try
> executing your program with './exp1.o'.
>
> rna
>
> On Wed, 16 Aug 2000, Eric Samson wrote:
>
> > Ok, this is frustrating...
> >
> > yesterday when I compiled some stuff I wrote in C++, I was able to run
> the
> > executable by typing exp1.o at the command prompt... Today, I tried it
> > again and got the following output:
> >
>  > []$ cd ~/C++assignments
>  > [C++assignments]$ g++ Assn2.cpp -oexp1.o
>  > [C++assignments]$ dir
>  > Assn2.cpp      Currency2-1.o         Currencycalc2-2.cpp   Currencycalc3.cpp
>  > Assn2.cpp~     Currency2-2.o         Currencycalc2-2.cpp~  exp1.o
>  > Currency1.cpp  Currencycalc2-1.cpp   Currencycalc2.cpp
>  > Currency1.o    Currencycalc2-1.cpp~  Currencycalc2.cpp~
>  > [C++assignments]$ exp1.o
>  > bash: exp1.o: command not found
>  > [C++assignments]$

> >
> > For some reason my compiled program won't run today, but it did yesterday
> > using the exact same commands. I love linux, but little inconsistent
> crap
> > like this is really aggrivating... I re-installed the gcc RPM's and
> > upgraded my BASH shell to no avail... I need some help here, or it's
> back
> > to M$ Visual C++ to get my school work done. I am trying to avoid this,
> > especially since I got done telling my class how great open source and
> Linux
> > are, but now I might have to eat my words next week... ANY help would be
> > appreciated..
> >
> > Thanks in advance,
> >
> > Eric
> >
> > ________________________________________________________________________
> > Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com
> >
> >
> > ________________________________________________
> > See http://PLUG.phoenix.az.us/navigator-mail.shtml if your mail doesn't
> post to the list quickly and you use Netscape to write mail.
> >
> > Plug-discuss mailing list -
> > http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss
> >
>
>
> ________________________________________________
> See http://PLUG.phoenix.az.us/navigator-mail.shtml if your mail doesn't post
> to the list quickly and you use Netscape to write mail.
>
> Plug-discuss mailing list -
> http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss
>
> ________________________________________________________________________
> Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com
>
>
> ________________________________________________
> See http://PLUG.phoenix.az.us/navigator-mail.shtml if your mail doesn't post to the list quickly and you use Netscape to write mail.
>
> Plug-discuss mailing list -
> http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss
>