0

I've tried to define structures of listNode, List and student and I get the error message:

Error   1   error LNK2019: unresolved external symbol _WinMain@16 referenced in       function ___tmainCRTStartup   C:\Users\Samsung\Documents\Visual Studio 2013\Projects\ICS Ex 03\ICS Ex 03\MSVCRTD.lib(crtexew.obj) ICS Ex 03 
Error   2   error LNK1120: 1 unresolved externals   C:\Users\Samsung\Documents\Visual Studio 2013\Projects\ICS Ex 03\Debug\ICS Ex 03.exe    ICS Ex 03

Here is the code:

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <malloc.h>
#include <math.h>

typedef struct list_node
{
    char*  dataPtr;
    struct list_node*  next;
}ListNode;

typedef struct list
{
    ListNode* head;
    ListNode* tail;
}List;

typedef struct  student
{
    List first;
    int grade;
} Student;




Student unScramble(List  lst);
List makeEmptyList(List* lst);
void insertDataToEndList(List *lst, char ch);
void printStudent(Student *student);
void freeList(List* lst);
int isEmptyList(List* lst);

void main()
{
    List lst;
    Student student;
    char ch;
    makeEmptyList(&lst);
    printf("Please enter the scrambled student:\n");
    ch = (char)getchar();
    while (ch != '\n')
    {
        insertDataToEndList(&lst, ch);
        ch = (char)getchar();
    }
    student = unScramble(lst);
    printStudent(&student);
    freeList(&student.first);
}
Student unScramble(List  lst)
{
    int num, count = 0;
    Student stu;
    stu.first = makeEmptyList(&stu.first);
    stu.grade = 0;
    if (*lst.tail->dataPtr >= '0' && *lst.tail->dataPtr <= '9')
    {
        num = (int)lst.tail->dataPtr - '0';
        stu.grade += (num*((int)pow(10, count)));
        count++;
    }
    /*if (lst.tail->dataPtr >= 'a' && lst.tail->dataPtr <= 'z')*/
    return stu;

}
List makeEmptyList(List* lst)
{
    lst->head = lst->tail = NULL;
    return *lst;
}
void insertDataToEndList(List *lst, char ch)
{
    ListNode *newHead;
    newHead = malloc(sizeof(ListNode));
    newHead->dataPtr = &ch;
    newHead->next = lst->head;
    if (lst->tail == NULL)
        lst->tail = newHead;
    lst->head = newHead;
}
void printStudent(Student *student)
{
    printf("Name: %s", student->first);
    printf("\n");
    printf("Grade: %s", student->grade);
}
void freeList(List *lst)
{
    ListNode *p, *q;

    if (isEmptyList(lst))
        return;

    p = lst->head;

    while (p->next != NULL)
    {
        q = p;
        p = p->next;
        free(q);
    }
    free(p);
}
int isEmptyList(List *lst)
{
    return (lst->head == NULL);
}

What went wrong?

  • 3
    I'm no expert on the weirdnesses of Windows, but the reference to an undefined `_WinMain16` suggests either you've omitted to write your `main()` function (you don't show it in your code), or you've managed to get the 'wrong options' in your compilation. I'm more inclined to think the problem is you've not yet written `main()`, but that's a guess. The code shown is fine; it just doesn't contain any functions yet. – Jonathan Leffler Mar 29 '14 at 16:48
  • at the beginning i had main and functions and the error occured so that's not it.. about the 2nd option, I didn't get it .. what do you mean wrong options? – MichaelKR142 Mar 29 '14 at 17:15
  • Then you've not shown us the code that is causing the problem, and we can't reasonably be expected to guess what the trouble is when we can't see the code that's causing the trouble. The only error appears to be that missing main-like name. If that's the only error message you got, the rest of the code was OK. And at that point, you need a Windows expert (or, at least, someone who has done some coding on Windows). That's not me. – Jonathan Leffler Mar 29 '14 at 17:18
  • About _Wrong options_: I don't know what is wrong if you have a `main()` function defined, but a C compiler is supposed to find `main()` and start execution there. However, the rules on Windows are different and complicated (and I don't know what they are and have no interest in finding out). To the limited extent I understand it, there are different entry points (names for the 'main function') depending on whether you're writing a console application running in a command window or something that runs in the Windows GUI world or something that runs as a service in the background. – Jonathan Leffler Mar 29 '14 at 17:22
  • Edited. Still same error. – MichaelKR142 Mar 29 '14 at 17:24
  • No idea; someone else will have to step in to help. I've tagged it Windows so maybe someone who knows will take a look at it and help. As it stands, I'd expect errors for undefined functions such as `freeList()`, `printStudent()`, `unScramble()`, etc. — and those appeared while I was typing. Out of my depth; Windows remains an incredibly hostile development environment AFAIAC. – Jonathan Leffler Mar 29 '14 at 17:26
  • His issue is specific for him. The code works fine for me. –  Mar 29 '14 at 17:48
  • @user3476192 what IDE you use? –  Mar 29 '14 at 17:49
  • You need to change your project from a Windows GUI project to a Windows console project. GUI programs use WinMain as their entry point. Note also that the error has nothing to do with the definition of your structures. Not sure why you think the structures have anything to do with it. – Raymond Chen Mar 29 '14 at 18:04
  • possible duplicate of [error LNK2019: unresolved external symbol \_WinMain@16 referenced in function \_\_\_tmainCRTStartup](http://stackoverflow.com/questions/6626397/error-lnk2019-unresolved-external-symbol-winmain16-referenced-in-function) – Raymond Chen Mar 29 '14 at 18:05
  • Raymond Chen, THANK YOU – MichaelKR142 Mar 29 '14 at 19:25

0 Answers0