#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define sg struct gammal
struct gammal {
char name[20];
int payment;
struct gammal *next;
};
void add (sg *g){
char name[20];
int payment;
printf("Enter Name: ");
scanf("%s",name);
printf("Enter Payment: ");
scanf("%d",&payment);
if(g->payment == -1){
strcpy(g->name,name);
g->payment = payment;
g->next = NULL;
}
else {
while(g->next != NULL)
g = g->next;
g->next = (sg*)malloc(sizeof(sg));
g = g->next;
strcpy( g->name,name);
g->payment = payment;
g->next = NULL;
}
}
void show (sg *g){
while ( g != NULL){
printf("---------");
printf("%s ",g->name);
printf("%d ",g->payment);
g = g->next;
}
}
int main()
{
sg *g =(sg*)malloc(sizeof(sg));
g->payment = -1;
add(g);
add(g);
show(g);
}