Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #9731

Re: I think this is an impossible assignment...could you help?

From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c
Subject Re: I think this is an impossible assignment...could you help?
Date 2011-08-31 09:18 +1200
Message-ID <9c52csF5dgU1@mid.individual.net> (permalink)
References <j3jj2t$eq3$1@speranza.aioe.org>

Show all headers | View raw


On 08/31/11 09:01 AM, Jack wrote:
> Ok, here's the deal...my instructor wants us to do the following
> program.  Only one problem:  what must I use to get this program to work
> right?  Do I use combinations of if, for and while statements, or just
> if statements or what?  I have tried nested if and while statements and
> CANNOT get the program to execute properly...  Perhaps an experienced
> programmer(unlike myself) could give me a little insight on how to do
> this problem...
> ANY help would greatly be appreciated.  If there's nething i can help
> someone else with...i will...THANK YOU
>
> COMSC 1613 Programming I (C)       Programming Assignment
> 3
>
> In this assignment, you will write a 'C' function that will approximate
> the action of the command scanf("%d",&x); namely, to read ASCII
> character
> digits from the standard input stream and convert/interpret the sequence
> into a binary integer.
>
> Consider the following implementation of main.
>
> #include
> #define INVALID     0x80000000
>
> long scan_int(void);               /* the prototype */
>
> int main(void)
> {long num, i;
> printf("\nenter an integer: ");
> for(i=1; (num = scan_int()) != -999; printf("\n\n\nenter an integer: "))
>     { if (num == INVALID)
>            printf("\n you entered an invalid sequence\n");
>       else
>            {
>              printf("\nthe %ld-th integer read was %ld\n", i, num);
>              ++i;
>            }
>       }
> return (0);

What awful style!

> }
>
> Use this main() as a driver.  You write function
>                 long scan_int(void);

Start of with your own main, calling scan_int for progressively more 
complex inputs, starting with one digit, then two or more then add a 
sign until you get the complete funtion:

int main(void)
{
   long result;

   puts("enter 1");

   assert( scan_int(void) == 1 );

   // start with the return here until this passes.

   puts("enter 11");

   assert( scan_int(void) == 11 );

   // then move it here and so on until all cases work.

   puts("enter -1");

   assert( scan_int(void) == -1 );

   // add more tests here.

   return 0;
}

-- 
Ian Collins

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

I think this is an impossible assignment...could you help? Jack <spamtrap@trashcan.invalid> - 2011-08-30 21:01 +0000
  Re: I think this is an impossible assignment...could you help? Ian Collins <ian-news@hotmail.com> - 2011-08-31 09:18 +1200
    Re: I think this is an impossible assignment...could you help? Jack <spamtrap@trashcan.invalid> - 2011-08-30 21:20 +0000
      Re: I think this is an impossible assignment...could you help? Ian Collins <ian-news@hotmail.com> - 2011-08-31 10:34 +1200
  Re: I think this is an impossible assignment...could you help? John Gordon <gordon@panix.com> - 2011-08-30 21:29 +0000
    Re: I think this is an impossible assignment...could you help? Jack <spamtrap@trashcan.invalid> - 2011-08-30 21:43 +0000
      Re: I think this is an impossible assignment...could you help? John Gordon <gordon@panix.com> - 2011-08-30 22:16 +0000
        Re: I think this is an impossible assignment...could you help? William Ahern <william@wilbur.25thandClement.com> - 2011-08-30 16:26 -0700
        Re: I think this is an impossible assignment...could you help? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-08-30 21:44 -0400
          Re: I think this is an impossible assignment...could you help? John Gordon <gordon@panix.com> - 2011-08-31 02:03 +0000
            Re: I think this is an impossible assignment...could you help? Keith Thompson <kst-u@mib.org> - 2011-08-31 08:56 -0700
              Re: I think this is an impossible assignment...could you help? John Gordon <gordon@panix.com> - 2011-08-31 16:15 +0000
                Re: I think this is an impossible assignment...could you help? Keith Thompson <kst-u@mib.org> - 2011-08-31 09:20 -0700
                Re: I think this is an impossible assignment...could you help? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-08-31 21:15 -0400
                Re: I think this is an impossible assignment...could you help? James Kuyper <jameskuyper@verizon.net> - 2011-08-31 22:18 -0400
                Re: I think this is an impossible assignment...could you help? blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-09-01 15:06 +0000
                Re: I think this is an impossible assignment...could you help? blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-09-01 15:04 +0000
                Re: I think this is an impossible assignment...could you help? John Gordon <gordon@panix.com> - 2011-09-01 15:20 +0000
                Re: I think this is an impossible assignment...could you help? David Thompson <dave.thompson2@verizon.net> - 2011-09-06 01:20 -0400
      Re: I think this is an impossible assignment...could you help? Keith Thompson <kst-u@mib.org> - 2011-08-30 16:37 -0700
      Re: I think this is an impossible assignment...could you help? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-08-31 00:51 +0100
        Re: I think this is an impossible assignment...could you help? blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-08-31 13:28 +0000
          Re: I think this is an impossible assignment...could you help? blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-09-01 15:03 +0000
            Re: I think this is an impossible assignment...could you help? Keith Thompson <kst-u@mib.org> - 2011-09-01 08:49 -0700
              Re: I think this is an impossible assignment...could you help? blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-09-02 07:46 +0000
            Re: I think this is an impossible assignment...could you help? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-09-01 21:30 -0400
              Re: I think this is an impossible assignment...could you help? blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-09-02 07:48 +0000
      Re: I think this is an impossible assignment...could you help? Ian Collins <ian-news@hotmail.com> - 2011-08-31 11:58 +1200
      Re: I think this is an impossible assignment...could you help? Ike Naar <ike@sverige.freeshell.org> - 2011-08-31 07:27 +0000
  Re: I think this is an impossible assignment...could you help? "BartC" <bc@freeuk.com> - 2011-08-31 10:37 +0100
    Re: I think this is an impossible assignment...could you help? blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-08-31 13:29 +0000
      Re: I think this is an impossible assignment...could you help? "BartC" <bc@freeuk.com> - 2011-08-31 18:41 +0100
        Re: I think this is an impossible assignment...could you help? blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-09-01 15:05 +0000
      Re: I think this is an impossible assignment...could you help? Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-09-02 01:42 -0700
    Re: I think this is an impossible assignment...could you help? Keith Thompson <kst-u@mib.org> - 2011-08-31 09:15 -0700
      Re: I think this is an impossible assignment...could you help? "BartC" <bc@freeuk.com> - 2011-08-31 18:36 +0100
        Re: I think this is an impossible assignment...could you help? Keith Thompson <kst-u@mib.org> - 2011-08-31 11:44 -0700
      Re: I think this is an impossible assignment...could you help? blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-09-01 15:05 +0000
        Re: I think this is an impossible assignment...could you help? Keith Thompson <kst-u@mib.org> - 2011-09-01 08:51 -0700
          Re: I think this is an impossible assignment...could you help? "BartC" <bc@freeuk.com> - 2011-09-01 17:26 +0100
            Re: I think this is an impossible assignment...could you help? blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-09-02 07:47 +0000
              Re: I think this is an impossible assignment...could you help? "BartC" <bc@freeuk.com> - 2011-09-02 10:56 +0100
                Re: I think this is an impossible assignment...could you help? blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-09-05 20:21 +0000
                Re: I think this is an impossible assignment...could you help? "Bartc" <bc@freeuk.com> - 2011-09-09 13:59 +0100
    Re: I think this is an impossible assignment...could you help? "BartC" <bc@freeuk.com> - 2011-09-02 10:43 +0100
  Re: I think this is an impossible assignment...could you help? Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2011-09-01 12:02 -0600
    Re: I think this is an impossible assignment...could you help? James Kuyper <jameskuyper@verizon.net> - 2011-09-01 15:12 -0400
      Re: I think this is an impossible assignment...could you help? sandeep <nospam@nospam.com> - 2011-09-01 19:36 +0000
      Re: I think this is an impossible assignment...could you help? Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2011-09-01 14:53 -0600
        Re: I think this is an impossible assignment...could you help? Keith Thompson <kst-u@mib.org> - 2011-09-01 16:01 -0700
          Re: I think this is an impossible assignment...could you help? Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2011-09-01 17:22 -0600
            Re: I think this is an impossible assignment...could you help? pete <pfiland@mindspring.com> - 2011-09-01 19:39 -0400
            Re: I think this is an impossible assignment...could you help? Keith Thompson <kst-u@mib.org> - 2011-09-01 16:39 -0700
              Re: I think this is an impossible assignment...could you help? Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2011-09-01 18:51 -0600
                Re: I think this is an impossible assignment...could you help? pete <pfiland@mindspring.com> - 2011-09-01 22:27 -0400
                Re: I think this is an impossible assignment...could you help? James Kuyper <jameskuyper@verizon.net> - 2011-09-01 22:53 -0400
                Re: I think this is an impossible assignment...could you help? Kenneth Brody <kenbrody@spamcop.net> - 2011-09-02 10:45 -0400
                Re: I think this is an impossible assignment...could you help? James Kuyper <jameskuyper@verizon.net> - 2011-09-02 11:02 -0400
                Re: I think this is an impossible assignment...could you help? Keith Thompson <kst-u@mib.org> - 2011-09-02 08:05 -0700
                Re: I think this is an impossible assignment...could you help? Keith Thompson <kst-u@mib.org> - 2011-09-02 08:17 -0700
                Re: I think this is an impossible assignment...could you help? Willem <willem@toad.stack.nl> - 2011-09-02 15:18 +0000
                Re: I think this is an impossible assignment...could you help? Keith Thompson <kst-u@mib.org> - 2011-09-02 08:42 -0700
            Re: I think this is an impossible assignment...could you help? James Kuyper <jameskuyper@verizon.net> - 2011-09-01 23:21 -0400
          Re: I think this is an impossible assignment...could you help? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-09-01 21:53 -0400
            Re: I think this is an impossible assignment...could you help? James Kuyper <jameskuyper@verizon.net> - 2011-09-01 23:09 -0400
    Re: I think this is an impossible assignment...could you help? Michael Press <rubrum@pacbell.net> - 2011-09-01 21:43 -0700
    Re: I think this is an impossible assignment...could you help? Keith Thompson <kst-u@mib.org> - 2011-09-02 08:32 -0700

csiph-web