LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Closed Thread
  Search this Thread
Old 08-06-2011, 05:34 AM   #1
mscoder
LQ Newbie
 
Registered: Jun 2011
Posts: 18

Rep: Reputation: Disabled
this code segment sticks in a loop when it enters the push() function....


int stack[100] and int top=-1 have been defined globally and "*array_stncnt" accepts pointer to an array of integers of size accepted by variable "count"...thanks in advance for your help...
Code:
void function(int count,int *array_stncnt)
{ 
        int i,n,index;
        int *p=array_stncnt;
        for(i=0;i<count;i++)
        {
                if(p[i]>=i)
                {
                        push(i);  /*Push called*/
                        push(p[i]);
                }
                else{}

        }

        while(top!=-1)
        {
                n=pop();
                index=pop();
                n=n-index;
                if(n>=index)
                {
                        push(index);
                        push(n);
                }
                else{}
                count++;
        }
        if(count%2==0)
        {
                printf("\nBOB WINS");
        }
        else
        {
                printf("\nALICE WINS");
        }

}



void push(int data)
{

                printf("\Push fn called\n");
                top++;
                stack[top]=data;
                printf("\nThe data aded to stack is %d",stack[top]);
}

int pop()
{
                int data;
                data=stack[top];
                top--;
                return(data);
}

Last edited by mscoder; 08-06-2011 at 05:37 AM.
 
Old 08-06-2011, 07:10 AM   #2
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
This thread is a duplicate of:
http://www.linuxquestions.org/questi...nction-895886/
 
  


Closed Thread

Tags
printf



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Not able to push arguments to a function from entry_32.S kamalsivadas Linux - Kernel 1 03-28-2011 10:56 AM
Kernel code segment write protection eagle_soaring_1 Linux - Kernel 1 02-28-2011 02:14 PM
[SOLVED] How to pass arguments to a function using a loop 10110111 Programming 2 03-01-2010 03:24 PM
how to print function names & parmaters each time control enters the function? tanniru Linux - Networking 1 09-11-2008 01:21 AM
Write to code segment Earp Programming 4 04-22-2004 01:49 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:52 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration