@all who have helped me the program has been solved perfectly, uploading the final code working like a charm thanks all, the last and prior errors can be clarified by the code.
Code:
#include<stdio.h>#include<strings.h>
#include<stdlib.h>
#include<malloc.h>
struct node
{
int data;
struct node *next;
};
typedef struct node link;
link create_link(link *r);
int main()
{
link *trys,*k;
int i,j,num;
trys=malloc(sizeof(link)); /*trys initialisation*/
k=trys;
printf("Enter the Number data\n");
scanf("%d",&num);
trys->data=num; /*store the number in trys*/
trys->next=NULL;
p: printf("\nDo you want to add more numbers?(Y=1/N=0)");
scanf("%d",&i);
if(i==1)
{
for(j=0;trys->next!=NULL;j++)
trys=trys->next; /*to send the pointer to last trys link for more addons*/
create_link(trys);
{
trys=k;
for(j=0;trys->next!=NULL;j++) /*moves the trys pointer to next links for adding numbers*/
trys=trys->next;
printf("\nEnter the next Number data\n");
scanf("%d",&num);
trys->data=num;
}
trys=k;
goto p;
}
else
{
printf("\nNumber dat entered by you is:\n");
printf("%d\n",(*trys).data); /*printing the first trys value*/
for(j=0;trys->next!=NULL;j++)
{
trys=trys->next; /*to increment the address of trys to next link*/
printf("%d\n",(*trys).data); /*printf takes value and not address*/
}
}
free(trys); /*freeing the malloc memory*/
return 0;
}
link create_link(link *r)
{
link *addon;
addon=malloc(sizeof(link));
r->next=addon;
addon->next=NULL;
return *r; /*return type needs to be juastified as type link*/
}