Donate to us via Paypal!
Things are more like they are now than they have ever been before. - Dwight D. Eisenhower
Sunday, February 28, 2021
Navigation
Home
 Find:
 Information:
Learn
Communicate
Submit
Shop
Challenges
 Exploit:
 Programming:
 Think:
 Track:
 Patch:
 Other:
 Need Help?
Other
Members Online
Total Online: 117
Guests Online: 117
Members Online: 0

Registered Members: 133756
Newest Member: Cleaners01
Latest Articles

View Thread

HellBound Hackers | Computer General | Programming

Author

An Exercise Using Pointers in C

Scar0ptics
Member



Posts: 229
Location: ∆ P®0X¥ W0R|D ∆
Joined: 19.11.13
Rank:
Mad User
Posted on 17-11-16 13:27
Given the following Point Struct Create 5 points and chain them together using the next pointer, then print them out using a while loop.

Struct Position {
int x;
int y;
point *next;

}

int main ( int argc, char **, argv) {

position a;
a.x = 100;
a.y = 200;

position a2;
a2.x = 1000;
a2.y = 2000;
a2.next = NULL;
a.next = &a2;

position a3;
a3.x = 10000;
a3.y = 20000;
a3.next = NULL;
a2.next = &a3;

position a4;
a4.x = 100000;
a4.y = 200000;
a4.next = NULL;
a3.next = &a4;

position a5;
a5.x = 1000000;
a5.y = 2000000;
a5.next = NULL;
a4.next = &a5;

position aa = &a;

while (aa != NULL) {

printf("%d,%d\n", aa->x, aa->y);
aa = aa->next;

}

}



That is my solution...Grin

Edited by Scar0ptics on 09-12-16 13:36
overlay-network.ddns.net
Author

RE: An Exercise Using Pointers in C

skeet
Member



Posts: 12
Location:
Joined: 26.01.16
Rank:
HBH Guru
Posted on 28-11-16 12:50
There is no #include

int main(int argc, char** argv) you had a random extra comma in there

all of your "position" declarations should be "point" because that's the name of the struct

return(0)
Author

RE: An Exercise Using Pointers in C

Scar0ptics
Member



Posts: 229
Location: ∆ P®0X¥ W0R|D ∆
Joined: 19.11.13
Rank:
Mad User
Posted on 28-11-16 13:50
I did not run this through a compiler before posting this. Thank you for spotting those small errors and I might just change "point" to "position".
overlay-network.ddns.net