c# - How do I change the address of a New struct in a loop? -


I am writing a simple program that is about polynomials using linked lists in C #. The problem I have is that whenever it creates a new straight (node) in the loop, it gives the same address as the previous node was given. How do I fix that? Here's my strait:

Structure Polly {Public Ent. Coffee; Public entity; Public shift * link;};

And here's the problem:

( ++) for i.e.textbox1.Text.Length; i ++) {q = New shift (); ... p- & gt; Link = & amp; Q; }

but & amp; Q remains unchanged!

Update:

To make it more clear, here is the full code:

Namespace PolyListProject {Unsecured Public Partial Class} Form 1: Form {Public Form 1 () {Initial Group (); } Structure shift {public int coef; Public entity; Public shift * link;}; Shift * start; Poly * p; Private Zero Button 1_Click (Object Sender, EventArgs E) {String Holder = ""; Shift q = new poly (); Start = & amp; Q; Int i = 0; While (this.Texbox 1. text [i]! = ',') {Holder + = this.Texbox1 Text [i]; I ++; } Q.coef = int.Parse (holder); I ++; Holder = ""; While (this.Texbox 1. text [i]! = ';' ') {Holder + = it.Texbox 1. text [i]; I ++; } Q.pow = int.Parse (holder); Holder = ""; P = start; // First node finished! I ++; For (; i & lt; this.textbox1.Text.Length; i ++) {q = new poly (); While (this.Texbox 1. text [i]! = ',') {Holder + = this.Texbox1 Text [i]; I ++; } Q.coef = int.Parse (holder); Holder = ""; I ++; While (this.Texbox 1. text [i]! = ';' '& Amp; amp; and & amp; i & lt; this.textbox1.Text.Length-1) {holder + = this.textbox1.Text [ I]; If (i & lt; this.textbox1.Text.Length-1) i ++; } Q.pow = int.Parse (holder); Holder = ""; P-> Link = q; } P-> Link = zero; }}}

Our professor has asked us to do in C. But we have decided to see it in C #, because no one is actually using C now. Does.

OK, because you are definitely using C ++, not C # I will answer in the context of C ++.

In this function, the q variable (I'm assuming), a pointer that is local for this function. This means that its address is not going to change.

The problem is that you can p-> Addressing an indicator on the link as new poly () already gives a shift * (which is an address!) You need an address is not.

Try this:

  q = new poly (); ... p- & gt; Link = q;  

Comments