Author Topic: Undefined Reference to "Function"  (Read 137 times)

Offline StarScream97

  • Single posting newcomer
  • *
  • Posts: 1
Undefined Reference to "Function"
« on: August 30, 2017, 02:57:08 pm »
I'm doing LinkedList in Codeblocks when i ran into errors while executing. It says "Undefined reference to function". "return type of main is not int". I also tried Eclipse and Netbeans to run my code but all of them showed the exact problem.

Here is my code:

#include <stdio.h>
#include<conio.h>
#include<stdlib.h>



 struct node{
    int data;
    struct node *next;

};
typedef struct node nodeType;

void insert_at_beginning();
void insert_at_end();
void insert_anywhere();
void del_first();
void del_last();
void del_anywhere();
void print();
void count_nodes();
void further();
int flag=1;

int val;
nodeType *temp,*head=NULL;


void main(){
int ch;
printf("1.Insert at 1st\n");
printf("2.Insert at last\n");
printf("3.Insert anywhere\n");
printf("4.Delete 1st\n");
printf("5.Delete last\n");
printf("6.Delete anywhere\n");
printf("7.Print the list\n");
printf("8.Count the # of nodes\n");
printf("Any other to exit\n");
printf("\n\nInput your choice\n");
scanf("%d",&ch);

while(flag==1)
{
    switch (ch)
    {
    case 1:
        insert_at_beginning();
        further();
        break;

    case 2:
        insert_at_end();
        further();
        break;

    case 3:
        insert_anywhere();
        further();
        break;

    case 4:
        del_first();
        further();
        break;
    case 5:
        del_last();
        further();
        break;

    case 6:
        del_anywhere();
        further();
        break;

    case 7:
        print();
        further();
        break;
    case 8:
        count_nodes();
        further();
        break;

    default:
        printf("Invalid Choice\n");
        further();
        break;
    }
    }
}

void insert_at_beginning()
{
printf("Insert a value to the list\n");
scanf("%d",&val);
nodeType *newnode;
newnode=(nodeType*)malloc(sizeof(nodeType));
newnode->data=val;
newnode->next=NULL;
head=newnode;


}

Please suggest a way to fix this problem.Its troubling me for quite a while now.
Thank you very much.





Offline BlueHazzard

  • Lives here!
  • ****
  • Posts: 1470
Re: Undefined Reference to "Function"
« Reply #1 on: August 30, 2017, 04:05:58 pm »
Quote
I'm doing LinkedList in Codeblocks
Wrong. You are "doing" a LinkedList in C . Codeblocks is just a IDE, like eclipse and Netbeans and not a compiler or programming language ...

Quote
I also tried Eclipse and Netbeans to run my code but all of them showed the exact problem
So if your code does not run in either of this IDEs this means your code is faulty. And according to the forum rules this kind of questions are not allowed here. I would suggest you go to a c support forum lick stackoverflow or cppboard or alike...

And if you go to this sites they probably want a build log. How you get it you can read here: http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_(general)#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F

[Edit:] And googling for 15 sec your error message will tell you what is wrong with your code.
« Last Edit: August 30, 2017, 04:08:00 pm by BlueHazzard »