首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误C3861:'initNode':未找到标识符

错误C3861:'initNode':未找到标识符
EN

Stack Overflow用户
提问于 2012-10-04 08:20:15
回答 1查看 7.6K关注 0票数 2

下面是编译错误:

错误C3861:'initNode':标识符未找到“

以下是代码:

代码语言:javascript
复制
# include <conio.h>
# include "stdafx.h"
# include <stdlib.h>

struct node{
    node * next;
    int nodeValue;

};

node*createList (int value)  /*Creates a Linked-List*/
{
    node *dummy_node = (node*) malloc(sizeof (node));
    dummy_node->next=NULL;
    dummy_node->nodeValue = value;
    return dummy_node;
}


void addFront (node *head, int num ) /*Adds node to the front of Linked-List*/
{
    node*newNode = initNode(num);   
    newNode->next = NULL;
    head->next=newNode;
    newNode->nodeValue=num;
}

void deleteFront(node*num)   /*Deletes the value of the node from the front*/
{
    node*temp1=num->next;

    if (temp1== NULL) 
    {
        printf("List is EMPTY!!!!");
    }
    else
    {
        num->next=temp1->next;
        free(temp1);
    }

}

void destroyList(node *list)    /*Frees the linked list*/
{
    node*temp;
    while (list->next!= NULL) 
    {
        temp=list;
        list=temp->next;
        free(temp);
    }
    free(list);
}

int getValue(node *list)    /*Returns the value of the list*/
{
    return((list->next)->nodeValue);
}


void printList(node *list)   /*Prints the Linked-List*/
{

    node*currentPosition;
    for (currentPosition=list->next; currentPosition->next!=NULL; currentPosition=currentPosition->next)  
    {`enter code here`
        printf("%d \n",currentPosition->nodeValue);
    }   
    printf("%d \n",currentPosition->nodeValue);

}

node*initNode(int number) /*Creates a node*/
{
    node*newNode=(node*) malloc(sizeof (node));
    newNode->nodeValue=number;
    newNode->next=NULL;
    return(newNode);
}

如何修复此错误?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-10-04 08:22:07

发生此错误是因为在调用initNode()之前它是不可见的。若要更正initNode()的声明,或将其定义移动到第一次使用之前。

代码看起来像C,但是您似乎正在使用C++编译器来编译它(因为使用node而不是struct node似乎不会导致编译器失败,除非您在文章中没有报告这些错误)。如果使用C编译器(可以通过使用Visual在源文件上使用.c扩展名轻松实现),则不需要强制转换malloc()的返回值。参见Incompatibilities Between ISO C and ISO C++ ,在回答问题What issues can I expect compiling C code with a C++ compiler?时找到的链接

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12723107

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档