Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

// why is temp2 not getting updated? It points to a[0].

struct man {
    int pos;
    struct man* next;
};



int main()
{

    int i;
    struct man* a[100];
    struct man* temp2;
    for (i=0;i<100;i++)
        {
            a[i] = (struct man*)malloc(sizeof(struct man));
            a[i]->pos = i+1;
        }




    for (i=0;i<100;i++)
        a[i]->next=a[(i+1)%100];





    struct man* temp = a[0];


    while (1)
    {

        temp->next = temp->next->next;
        if(temp->next==temp) {
         temp2=temp;
            break;
        }
    }


    printf("%d",temp2->pos);

    return 0;
}
share|improve this question

closed as off-topic by Mast, Mat's Mug May 30 at 15:31

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions containing broken code or asking for advice about code not yet written are off-topic, as the code is not ready for review. After the question has been edited to contain working code, we will consider reopening it." – Mast, Mat's Mug
If this question can be reworded to fit the rules in the help center, please edit the question.

    
Questions containing broken code or asking for advice about code not yet written are off-topic, as the code is not ready for review. After the question has been edited to contain working code, we will consider reopening it. – Mast May 30 at 15:30

Browse other questions tagged or ask your own question.