Re: App won't exit correctly

From: John Harrison (john_andronicus_at_hotmail.com)
Date: 03/31/04


Date: Wed, 31 Mar 2004 10:13:19 +0100


"..." <...@...> wrote in message
news:fd469b011f3208ab97e16cf1850ac94d@news.teranews.com...
>
>
> OK, Below is the code for the program I have written. It's purpose is to
> take an ISBN number as
>
> input and run it through as series of checks to confirm that it is a valid
> ISBN number. The last part
>
> of the function confirms if the check bit (last number) is correct as
> determined by the
>
> previous 9 numbers. The program seems to work fine; however, when compiled
> and run on a Unix
>
> box it doesn't seem to exit correctly.
>
>
>
> For anyone that is willing to offer help, I'm not just looking for
> corrections. I'd appreciate an explanation
>
> of where I have gone wrong and how I could improve my code.
>

Bit of mystery. I can see a few improvements, for instance this

  int temp = atoi (&(identTest.c_str())[n]);
  temp = temp / int(pow (10.0, (8.0 - n)));

can be replaced with the much simpler and more efficient

  int temp = identTest[n] - '0';

Also you spend all that time returning a value from format_ok, but then you
never test that value in main. I would expect to see something like this

int main
{
    ...
    if (format_ok(ISBNin))
        cout << "the format is ok\n";
    else
        cout << "the format is bad\n";
}

rather than printing the message in format_ok.

But I can't see anything that would cause the problems you've described. It
compiles and runs correctly on my compiler. I'll test it on g++ when I get
the chance, which version of g++ are you using?

john



Relevant Pages

  • VB 6 Crystal Printing Issues
    ... We have just moved into an environment where all compiles / builds will be ... done on PCs specifically for that purpose. ... uses Crystal for reporting capabilities. ... to do a file by file compare on the control files. ...
    (microsoft.public.vb.crystal)
  • Re: Function templates
    ... > such a way that it only compiles with compatible types. ... You can also restrict T for the purpose of guiding overload resolution ...
    (comp.lang.cpp)
  • Re: unbuffered file IO?
    ... I dare say it *compiles* fine, but it doesn't look exactly general ... purpose to me. ... buffer, read into it, and then convert the *whole* buffer into a ...
    (microsoft.public.dotnet.languages.csharp)
  • IIS 5.0 WebDAV -Proof of concept-. Fully documented.
    ... I wrote another exploit for the nt.dll bug some days ago. ... Explanation and a little documentation is included in the source ... It compiles in Linux/gcc without any error. ...
    (Bugtraq)

Loading