PLEASE PLEASE HELP HELP...question on interleaving C functions 
Author Message
 PLEASE PLEASE HELP HELP...question on interleaving C functions

The scenario...

main()
{

sub1(parameters);
sub2(parameters);

Quote:
}

sub1(...)
{
..some statemenmts

Quote:
}

sub2(...)
{
..some statements

Quote:
}

I intend main to call sub1, such that sub1 executes ONLY 1 INSTRUCTION, &
returns control to main.
Main then calls sub2, which again executes a single instrcution & returns.
Main then calls sub1, which executes the next instruction ( only 1 again)
and returns to main.
Main thus calls sub1, sub2, sub1, sub2 alternately until both sub1 & sub2
run out of instructions.

How do I accomplish this act? The problem boils down to this...
After entering sub1, AN INSTRUCTION must be executed, there must be a mechanism
to remember which that instrcution was, so that the next time sub1 is called,
the instruction following the already executed one is processed.
Also, after each instruction, how do I return back to main?

In reality, sub1 & sub2 are two sorting routines that I coded up using
graphics.h in Turbo C.
The Professor was impressed with the fact that mergesort & insertion sort
could be demonstrated graphically, but wasn't by the fact that you couldn't
view both at the same time!

I suppose that if the above concept were clarified, it could be suitably
generalized and adopted in this and similar problems.

C gurus, please don't let me down this time....!


Thank you in advance......Krish.



Wed, 17 Jun 1998 03:00:00 GMT  
 PLEASE PLEASE HELP HELP...question on interleaving C functions

Quote:

>The scenario...
>main()
>{
>sub1(parameters);
>sub2(parameters);
>}
>sub1(...)
>{
>..some statemenmts
>}
>sub2(...)
>{
>..some statements
>}
>I intend main to call sub1, such that sub1 executes ONLY 1 INSTRUCTION, &
>returns control to main.
>Main then calls sub2, which again executes a single instrcution & returns.
>Main then calls sub1, which executes the next instruction ( only 1 again)
>and returns to main.
>Main thus calls sub1, sub2, sub1, sub2 alternately until both sub1 & sub2
>run out of instructions.

try something like this

#define DONE 1
#define NOT_DONE 0
int sub1()
  {
  static int instruction = 1;
  switch(instruction)
    {
     case 1:
       [first instruction];
       break;
    case 2:
       [second instruction];
       break;
    ...
    deafult:
      return DONE;
    }
 instruction++;
 return NOT_DONE;
 }

Sub2 would look just like sub1 but with different instructions. Your
main could look like...

main()
  {
  do
    {
    done1 = sub1();
    done2 = sub2();
    } while(!done1 && !done2);
  }

This ought to do the trick for you, but document carefully that the
cases in sub1 and sub2 are always executed in order starting with case
1. I actually used something like this once. It does the job but it is
sort a maintenance headache since it is not immediatley obvious what
is going on.

Harold Putman              
InterBold Dept. 9-52       /  IBMMAIL:    USZVNWGN

North Canton, OH  44720    /  CompuServe: 73744,2632
USA                        /  Tel: (216) 490-4723  FAX: (216) 490-4508



Mon, 29 Jun 1998 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!

2. Please help!!!!Please help!!!!Please help!!!!

3. NEED HELP WITH PRITING AN ARRAY, PLEASE PLEASE HELP

4. help: Guru needed please please please

5. HELP please on QUEUES!! please, please, please, please,please...

6. help: basic stupid questions, please help tho

7. Please Please Help!!!!!!

8. ICloneable - Please help.....please....

9. simulate dragDrop of ListView Item -- Please Please Help!!!!

10. Very Urgent !!! please please help

11. SOMEONE HELP ME, HELP ME, HELP ME PLEASE...

12. HELP HELP HELP ME PLEASE!!

 

 
Powered by phpBB® Forum Software