[ create a new paste ] login | about

Link: http://codepad.org/1439V0cn    [ raw code | output | fork ]

iamyeasin - C++, pasted on Feb 15:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main()
{
    struct point // For node
    {
        int x;
        int y;

        struct point *p; // This will store next address of the node
    };

    typedef struct point pt; // Creating a variable for the node

    int i;

    pt *mp = (pt*) malloc(sizeof(pt)); // Defining Head node as NULL
    pt *star = mp; // Storing the head node into the star

    for(i=0; i<3; i++)
    {
        scanf("%d %d",&mp->x,&mp->y); //Taking input for the first two points
        mp -> p = (pt*)malloc(sizeof(pt)); // creating another node

        mp = mp->p; // storing the address

    }

    mp -> p = NULL; // The last node is NULL. Putting a terminal value
    mp = star; // Now initializing the head into the pointer


    while(mp->p) // While there is node print the values
    {
        printf("%d %d\n",mp->x,mp->y);
        mp = mp->p;
    }




    return 0;
}


Output:
1
2
3
-1819044973 -1819044973
-1819044973 -1819044973
-1819044973 -1819044973


Create a new paste based on this one


Comments: