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

  • Home
  • SEARCH
  • 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
  • 2 Views
  • 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

Related Questions

I'm working with a webservice that offers almost duplicated code across two namesspaces. Lets
I got some legacy code with that caption spread out as comment almost in
I'm almost finished with my program, but I have one problem that I can't
I've been writing C / C++ code for almost twenty years, and I know
I have the following code in my Site.Master page of an almost empty ASP.NET
I've almost finished writing a HTTP/1.0 compliant web server under Java (no commercial usage
I am almost finished changing a cursor-based stored procedure over to set-based. Almost, because
Here's the site in question: http://cbcsettlementfunding.com/dev/ Almost finished up with development, just have a
I have a php application that has about 50-55 code files. The file that
Code below does not run correctly and throws InvalidOperationExcepiton . public void Foo() {

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.