1

I'm new at c programming, and during my learnings, lately I've started to deal with Linked lists. In this program that I wrote, i keep getting this message( LNK2019 error):

   unresolved external symbol _main referenced in function "int __cdecl  invoke_main(void)" (?invoke_main@@YAHXZ)

What I'm trying to do is to create a linked list, and use a function to input values into this list, using the main.

this is the full code I wrote:

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

typedef struct Original_list
{
  int data;
  struct Original_list *next;
}original_list;

original_list *Input();

void EX2()
{
  original_list *list;
  list = Input();

}

original_list *Input()
{
   original_list *lst, *curr_point;
   int c;
   printf("Please enter a value to the first data: \n");
   scanf_s("%d", &c);
   if (c < 0)
      return NULL;
   lst = (original_list*)malloc(sizeof(original_list));
   curr_point = lst;
   lst->data = c;

   while (c >= 0)
   {
     curr_point->next = (original_list*)malloc(sizeof(original_list));
     curr_point = curr_point->next;
     curr_point->data = c;
     printf("please enter number(scan will stop if a negative number is scanned): \n");
     scanf_s("%d", &c);
   }
   curr_point->next = NULL;
   return lst;
}

I can't see any definition I did wrong or any problem justifying this error.

please help!

thank you very much!

Ori
  • 13
  • 4
  • 1
    Welcome to StackOverflow! Can you please share the content of your `main()` function? – José Luis Apr 11 '18 at 11:35
  • Sorry about that, it was unclear. my `main()` function was the `void EX2()`. changed the name to `main()`and that fixed the problem. – Ori Apr 11 '18 at 12:48

2 Answers2

1

Your code lacks an entry point. For C/C++ it is usually main(), that's what the error is about.

vsenko
  • 1,129
  • 8
  • 20
0

Check the projects configuration and make sure that you have set

Linker > System > Subsystem

to 'Console'. The issue occurs when it is set to 'Windows'.

Thomas Flinkow
  • 4,845
  • 5
  • 29
  • 65
  • i was on console at first.. thank you for your answer! the problem was the name of the main... "EX2" instead of "main" – Ori Apr 11 '18 at 11:44