By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,987 Members | 971 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,987 IT Pros & Developers. It's quick & easy.

what is the problem in this code?

P: 1
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. struct Node
  4. {
  5.     int data;
  6.     struct Node *add;
  7. };
  8. void insert(struct Node **,int );
  9. void main()
  10. {
  11.     int pos,value;
  12.     struct Node* head=NULL; struct Node *point;
  13.     insert(&head,10);
  14.     insert(&head,20);
  15.     insert(&head,30);
  16.     insert(&head,40);
  17.     insert(&head,50);
  18.     insert(&head,60);
  19.     insert(&head,70);
  20.     insert(&head,80);
  21.     insert(&head,90);
  22.     insert(&head,100);
  23.     printf("Enter the position from the last to be displayed:");
  24.     scanf("%d",&pos);
  25.     point=display_nth(head);
  26.     value=point->data;
  27.     printf("\n%dth value for nth node is %d",pos,value);
  28.     display(head);
  29. }
  30. insert(struct Node** ref_head,int new_data)
  31. {
  32.     struct Node* temp=(struct Node*)malloc(sizeof(struct Node));
  33.     temp->data=new_data;
  34.     temp->add=(*ref_head);
  35.     (*ref_head)=temp;
  36. }
  37.  
31 1 C:\Users\GARIMA\Documents\nth from last.c [Warning] conflicting types for 'insert' [enabled by default]
8 6 C:\Users\GARIMA\Documents\nth from last.c [Note] previous declaration of 'insert' was here
C:\Users\GARIMA\AppData\Local\Temp\ccqujr3n.o nth from last.c:(.text+0x116): undefined reference to `display'
C:\Users\GARIMA\Documents\collect2.exe [Error] ld returned 1 exit status
Sep 23 '18 #1
Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,197
In the function prototype insert() returns void.

In the function definition insert() return int.

oops.

When the return type is not specified, it defaults to int.

BTW: main() returns int. Not void. main() is the only function that returns int and you don't need a return statement.
Sep 23 '18 #2

Post your reply

Sign in to post your reply or Sign up for a free account.