[ create a new paste ] login | about

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

iamyeasin - C++, pasted on Mar 3:
#include<stdio.h>
#include<stdlib.h>
#define pf printf
#define sc scanf

struct node
{
    char ch[100];
    int age;
    struct node *next;//Creating a self referential pointer
};

typedef struct node type;

type *head = (type*)malloc(sizeof(type));
type *start = head;

void takeIn()
{
    int n;
    pf("Enter how many nodes you want to take in: ");
    sc("%d",&n);

    for(int i=0; i<n; i++)
    {
        scanf(" %[^\n]",&head->ch);///Take a input of hole line
        scanf("%d",&head->age);
        head->next = (type*)malloc(sizeof(type));
        head = head->next;
    }

    head->next= NULL;
}

void display()
{
    pf("The condition of the linked list: \n");
    type *st = start;
    while(st->next)
    {
        puts(st->ch);;
        pf("%d\n",st->age);
        st=st->next;
    }

}

type *find_adrs(int itm,int pos)
{
    type *st = start;
//    type *noItem = NULL;
    if(st->age == itm)
    {
       if(pos == 1)  return NULL;
       else if(!pos)  return st;
       else if(pos==2)  return st->next;
    }


    while(st->next)
    {
        if(st->next->age == itm)
        {
            if(pos == 1)
            {
                return st;
            }
            else if(pos == 0)
            {
                return st->next;
            }
            else if(pos == 2)
            {
                return st->next->next;
            }
        }
        st = st->next;
    }

    return NULL;
}


void insert_first()
{
    pf("Enter value for new node adding to the first of the node: \n");
    type *newNode = (type*)malloc(sizeof(type));
    sc(" %[^\n]",&newNode->ch);
    sc("%d",&newNode->age);
    newNode->next = start;
    start = newNode;
}

void insert_last()
{
    type *newNode = (type*)malloc(sizeof(type));
    type *st = start;//starting again from the start node.

    while(st->next)
    {
        st = st->next;// this will make me to reach at the last node
    }

    st->next = newNode;
    pf("Enter the values to add values to the last of the linked list: \n");

    sc(" %[^\n]",&st->ch); // This must be from st. because st reached at the last point. then st has to add the values
    sc("%d",&st->age);
    newNode->next = NULL;
}

void insert_middle()
{
    int age,n;
    type *st = (type*)malloc(sizeof(type));



}



int main()
{
    takeIn();
//    insert_first();
//    insert_last();
//    display();
    insert_middle();

    return 0;
}


Output:
1
2
3
4
5
6
7
8
9
10
cc1plus: warnings being treated as errors
In function 'void takeIn()':
Line 26: warning: format '%[^
' expects type 'char*', but argument 2 has type 'char (*)[100]'
In function 'void insert_first()':
Line 88: warning: format '%[^
' expects type 'char*', but argument 2 has type 'char (*)[100]'
In function 'void insert_last()':
Line 107: warning: format '%[^
' expects type 'char*', but argument 2 has type 'char (*)[100]'


Create a new paste based on this one


Comments: