Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 805657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:06:58+00:00 2026-05-15T00:06:58+00:00

My code was almost finished that a maddening bug came up! When I nullify

  • 0

My code was almost finished that a maddening bug came up! When I nullify the last node to finalize the link list , it actually dumps all the links and make the first node link Null !
when i trace it , its working totally fine creating the list in the loop but after the loop is done that happens and it destroys the rest of the link by doing so, and i don’t understand why something so obvious is becoming problematic!
(last line)

struct poly { public int coef; public int pow; public poly* link;} ;
        poly* start ;
        poly* start2;
        poly* p;
        poly* second;
        poly* result;
        poly* ptr;
        poly* start3;
        poly* q;
        poly* q2;
        private void button1_Click(object sender, EventArgs e)
        {
            string holder = "";
            IntPtr newP = Marshal.AllocHGlobal(sizeof(poly));
            q = (poly*)newP.ToPointer();
            start = q;
            int i = 0;
            while (this.textBox1.Text[i] != ',')
            {
                holder += this.textBox1.Text[i];
                i++;
            }
            q->coef = int.Parse(holder);
            i++;
            holder = "";
            while (this.textBox1.Text[i] != ';')
            {
                holder += this.textBox1.Text[i];
                i++;
            }
            q->pow = int.Parse(holder);
            holder = "";
            p = start;
            //creation of the first node finished!
            i++;
            for (; i < this.textBox1.Text.Length; i++)
            {
                newP = Marshal.AllocHGlobal(sizeof(poly));
                poly* test = (poly*)newP.ToPointer();
                while (this.textBox1.Text[i] != ',')
                {
                    holder += this.textBox1.Text[i];
                    i++;
                }
                test->coef = int.Parse(holder);
                holder = "";
                i++;

                while (this.textBox1.Text[i] != ';' && i < this.textBox1.Text.Length - 1)
                {
                    holder += this.textBox1.Text[i];
                    if (i < this.textBox1.Text.Length - 1)
                        i++;
                }
                test->pow = int.Parse(holder);
                holder = "";
                p->link = test;    //the addresses are correct and the list is complete
            }
            p->link = null;        //only the first node exists now with a null link!
}
  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T00:06:59+00:00Added an answer on May 15, 2026 at 12:06 am

    p always holds reference to the first element, so yes, p->link = null; does exactly what you said. It seems to me that you wanted something like this :

        ...
        p->link = test;
        p = test;
        ....
    

    Edit :

    Proof of concept

    public unsafe struct poly { public int coef; public int pow; public poly* link; }
    
    public unsafe class Program
    {
        static void Main(string[] args)
        {            
            poly* temp1, temp2, start =
                (poly*)Marshal.AllocHGlobal(sizeof(poly)).ToPointer();
            start->coef = 0;
            start->pow = 0;
            temp1 = start;
            for (int i = 1; i < 10; i++)
            {
                temp2 = (poly*)Marshal.AllocHGlobal(sizeof(poly)).ToPointer();
                temp2->coef = i;
                temp2->pow = i;
                temp1->link = temp2;
                temp1 = temp2;
            }
            temp1->link = null;
            temp1 = start;
    
            while (temp1 != null)
            {
                Console.WriteLine(
                    string.Format(
                        "eoef:{0}, pow:{1}", 
                        temp1->coef, 
                        temp1->pow));
                temp1 = temp1->link;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 417k
  • Answers 417k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer For 24bit colors (8 bits to each of R,G,B): String… May 15, 2026 at 9:45 am
  • Editorial Team
    Editorial Team added an answer Your problem is that you want the "Where" condition to… May 15, 2026 at 9:45 am
  • Editorial Team
    Editorial Team added an answer It all depends on the load of your site, but… May 15, 2026 at 9:45 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.