大头飞飞 2020-12-21 06:20 采纳率: 50%
浏览 38
已采纳

请教各位大神 VS 2012 中erro LNK 1120 , 2001, 2019报错如何解决

问题描述:我在VS 2012中进行队列的练习(C Primer plus第6版 P594-P598)时,按照书上的示例将程序敲入电脑后运行,系统提示这三个报错eorr LNK1120, 2001, 2019. 具体报错信息请见截图。 尝试了很多论坛中的方法,但是都不能解决。

报错截图:

NA

代码段如下:

queue.h文件中的代码:

/* P593-queue.h */
#ifndef _QUEUE_H_
#define _QUEUE_H_

typedef int Item;
#define MAXQUEUE 10

typedef struct node {
	Item item;
	struct node * next;
}Node;

typedef struct queue
{
	Node * front;
	Node * rear;
	int items;
} Queue;


/* Operation: Initialize Queue */
/* Precondition: pq ponit to a queue */
/* Postcondition: The queue will be set to NULL */

void InitializeQueue(Queue * pq);


/* Operation: Confirm whether the queue is full */
/* Precondition: pq point to an initialized queue */
/* Postcondition: If the queue is full, return 1, otherwise return 0 */

int QueueIsFull(const Queue * pq);


/* Operation: Confirm whether the queue is empty */
/* Precondition: pq point to an initialized queue */
/* Postcondition: If the queue is empty, return 1, otherwise return 0 */

int QueueIsEmpty(const Queue * pq);

/* Operation: Count the number of the queue */
/* Precondtion: pq point to an initialized queue */
/* Postcondition: Return the number of items in the queue */

int QueueItemCount(const Queue * pq);

/* Operation: Add an item to the end of a queue */
/* Precondition: pq point to an initialized queue */
/*               item is to be added to the end of a queue */
/* Postcondition: If the queue is not empty, item will be added to the end of the queue */
/*                if success, return 1, otherwise, return 0 with the current queue unchanged. */

int EnQueue(Item item, Queue * pq);

/* Operation: Delete the item from the front of the queue */
/* Precondition: pq point to an initialized queue */
/* Postcondition: If the queue is not empty, the front of the queue will be copied to *pitem */
/*                and it will be deleted, meanwhile the function return 1 */
/*                If this operation makes queue to be empty, Initialize the queue */
/*                If the queue is empty before operation, the function return 0   */
int DeQueue(Item *pitem, Queue * pq);


/* Operation: Clear the queue */
/* Precondition: pq point to an initialized queue */
/* Postcondition: The queue will be cleared */
void EmptyQueue(Queue * pq);

#endif

queue.c中的代码:

/* P596-queue.c */

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


/* regional function */
static void CopyToNode (Item item, Node * pn);
static void CopyToItem(Node * pn, Item * pi);

void InitializeQueue(Queue * pq)
{
	pq->front = pq->rear = NULL;
	pq->items = 0;
}

int QueIsFull(const Queue * pq)
{
	int res;
	if (pq->items == MAXQUEUE)
		res = 1;
	else
		res = 0;
	return res;
}

int QueueIsEmpty(const Queue * pq)
{
	int res;
	if (pq->items == 0)
		res = 1;
	else
		res = 0;

	return res;
}

int QueueItemCount(const Queue * pq)
{
	return pq->items;
}

int EnQueue(Item item, Queue * pq)
{
	Node * pnew;
	int res;

	if (QueueIsFull(pq) == 1)
		res = 0;
	else
	{
		res = 1;
		pnew = (Node *)malloc(sizeof(Node));
		if (pnew == NULL)
		{
			fprintf(stderr, "Unable to allocate memory!\n");
			exit(EXIT_FAILURE);
		}
		CopyToNode(item, pnew);
		pnew->next = NULL;
		if (QueueIsEmpty(pq) == 1)
			pq->front = pnew;
		else
			pq->rear->next = pnew;
		pq->rear = pnew;
		pq->items++;
	}

		return res;
}

int DeQueue(Item * pitem, Queue * pq)
{
	Node * pt;
	int res;

	if(QueueIsEmpty(pq) ==1 )
		res = 0;
	else
	{
		res = 1;
		CopyToItem(pq->front, pitem);
		pt = pq->front;
		pq->front = pq->front->next;
		free(pt);
		pq->items--;
		if (pq->items == 0)
			pq->rear = NULL;
	}
	return res;
}

void EmptyQueue(Queue * pq)
{
	Item dummy;
	while (!QueueIsEmpty(pq))
		DeQueue(&dummy, pq);
}



static void CopyToNode(Item item, Node * pn)
{
	pn->item = item;
}

static void CopyToItem(Node * pn, Item * pi)
{
	*pi = pn->item;
}


use_q.c中的代码:

/* P598 use_q.c */
#include <stdio.h>
#include <stdlib.h>
#include "queue.h"


int main (void)
{
	Queue line;
	Item temp;
	char ch;


	InitializeQueue(&line);
	puts("Testing the queue interface. Type a to add a value, ");
	puts("type d to delete a value, and type q to quit.");
	while ((ch = getchar()) != 'q')
	{
		if (ch != 'a' && ch != 'd')
			continue;
		if (ch == 'a')
		{
			printf("Integer to add: ");
			scanf("%d", &temp);
			if (QueueIsFull(&line) == 0)
			{
				printf("Putting %d into queue.\n", temp);
				EnQueue(temp, &line);
			}
			else
			{
				puts("Queue is full!");
			}
		}
		else
		{
			if (QueueIsEmpty(&line) == 1)
				puts("Nothing to delete!");
			else
			{
				DeQueue(&temp, &line);
				printf("Removing %d from queue.\n", temp);
			}
		}
		printf("%d items in queue\n", QueueItemCount(&line));
		puts("Type a to add, d to delete, q to quit:");
	}
   EmptyQueue(&line);
	puts("Bye!");

	return 0;
}
  • 写回答

4条回答 默认 最新

  • 平安格勒_星 2020-12-21 09:38
    关注

    queue.c第18行  拼写错了吧

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)