我尝试定义listNode
,List
和student
的结构
我收到错误消息:
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
以下是代码:
#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);
}
出了什么问题?