yuqiuwangzi 发表于 2013-11-18 11:36:41

VS2010编译不了VC6的代码

   如题,敲了一段栈程序代码,VC++6.0成功编译通过,但VS2010总是提示有错,不兼容么?

yuqiuwangzi 发表于 2013-11-18 12:58:23

坐等高手出现。。。

friendan 发表于 2013-11-18 13:16:59

能否贴一下代码和错误提示。

yuqiuwangzi 发表于 2013-11-18 13:52:35

本帖最后由 yuqiuwangzi 于 2013-11-18 13:53 编辑

friendan 发表于 2013-11-18 13:16 static/image/common/back.gif
能否贴一下代码和错误提示。
# include <stdio.h>
# include <malloc.h>
# include <stdlib.h>

typedef struct Node
{
      int data;
      struct Node * pNext;
}NODE, * PNODE;

typedef struct Stack
{
      PNODE pTop;
      PNODE pBottom;
}STACK, * PSTACK;//PSTACK 等价于 struct STACK *

void init(PSTACK);
void push(PSTACK, int );
void traverse(PSTACK);
bool pop(PSTACK, int *);
void clear(PSTACK pS);

int main(void)
{
      STACK S;//STACK 等价于 struct Stack
      int val;

      init(&S);//目的是造出一个空栈
      push(&S, 1); //压栈
      push(&S, 2);
      push(&S, 3);
      push(&S, 4);
      push(&S, 5);
      push(&S, 6);
      traverse(&S); //遍历输出
      
      clear(&S);
      //traverse(&S); //遍历输出

      if ( pop(&S, &val) )
      {
                printf("出栈成功,出栈的元素是%d\n", val);
      }
      else
      {
                printf("出栈失败!\n");
      }

      traverse(&S); //遍历输出

      return 0;
}

void init(PSTACK pS)
{
      pS->pTop = (PNODE)malloc(sizeof(NODE));
      if (NULL == pS->pTop)
      {
                printf("动态内存分配失败!\n");
                exit(-1);
      }
      else
      {
                pS->pBottom = pS->pTop;
                pS->pTop->pNext = NULL; //pS->Bottom->pNext = NULL;
      }
}

void push(PSTACK pS, int val)
{
      PNODE pNew = (PNODE)malloc(sizeof(NODE));
      
      pNew->data = val;
      pNew->pNext = pS->pTop; //pS->Top不能改成pS->Bottom
      pS->pTop = pNew;

      return;
}

void traverse(PSTACK pS)
{
      PNODE p = pS->pTop;

      while (p != pS->pBottom)
      {
                printf("%d", p->data);
                p = p->pNext;
      }
      printf("\n");

      return;
}

bool empty(PSTACK pS)
{
      if (pS->pTop == pS->pBottom)
                return true;
      else
                return false;
}

//把pS所指向的栈出栈一次,并把出栈的元素存入pVal形参所指向的变量中,如果出栈失败,返回false,否则返回true
bool pop(PSTACK pS, int * pVal)
{
      if ( empty(pS) ) //pS本身存放的就是S的地址
      {
                return false;
      }
      else
      {
                PNODE r = pS->pTop;
                *pVal = r->data;
                pS->pTop = r->pNext;
                free(r);
                r = NULL;

                return true;
      }
}

//clear清空
void clear(PSTACK pS)
{
      if (empty(pS))
      {
                return;
      }
      else
      {
                PNODE p = pS->pTop;
                PNODE q = NULL;

                while (p != pS->pBottom)
                {
                        q = p->pNext;
                        free(p);
                        p = q;
                }
                pS->pTop = pS->pBottom;
      }
}循环队列.c(20): error C2061: 语法错误: 标识符“pop”
循环队列.c(20): error C2059: 语法错误:“;”
循环队列.c(20): error C2059: 语法错误:“类型”
循环队列.c(40): warning C4013: “pop”未定义;假设外部返回 int
循环队列.c(94): error C2061: 语法错误: 标识符“empty”
循环队列.c(94): error C2059: 语法错误:“;”
循环队列.c(94): error C2059: 语法错误:“类型”
循环队列.c(103): error C2061: 语法错误: 标识符“pop”
循环队列.c(103): error C2059: 语法错误:“;”
循环队列.c(103): error C2059: 语法错误:“类型”
循环队列.c(124): warning C4013: “empty”未定义;假设外部返回 int
1>
1>生成失败。
1>


猪猪BBUn咕咕 发表于 2013-11-18 15:19:30

你注意一下你的头文件

猪猪BBUn咕咕 发表于 2013-11-18 15:20:17

把那些什.h的都去掉

猪猪BBUn咕咕 发表于 2013-11-18 15:23:54

我的可以成功运行啊~~~我运行过

friendan 发表于 2013-11-18 18:35:50

我用VS2010编译了一下你的代码没错哦。

yuqiuwangzi 发表于 2013-11-18 23:06:51

猪猪BBUn咕咕 发表于 2013-11-18 15:23 static/image/common/back.gif
我的可以成功运行啊~~~我运行过

为毛啊。。。提示的那些错误我看根本就没错。。。这软件应该没问题才对

yuqiuwangzi 发表于 2013-11-18 23:09:30

friendan 发表于 2013-11-18 18:35 static/image/common/back.gif
我用VS2010编译了一下你的代码没错哦。

那我这怎么回事啊,莫非是软件问题?

friendan 发表于 2013-11-18 23:21:11

yuqiuwangzi 发表于 2013-11-18 23:09 static/image/common/back.gif
那我这怎么回事啊,莫非是软件问题?

你写个简单的类似hello world之类的测试一下看看。

yuqiuwangzi 发表于 2013-11-18 23:25:11

friendan 发表于 2013-11-18 23:21 static/image/common/back.gif
你写个简单的类似hello world之类的测试一下看看。

试过了,hello world这类简单的没问题

friendan 发表于 2013-11-18 23:29:24

yuqiuwangzi 发表于 2013-11-18 23:25 static/image/common/back.gif
试过了,hello world这类简单的没问题

添加以下语句看看:

#include "stdafx.h"

yuqiuwangzi 发表于 2013-11-19 00:11:22

friendan 发表于 2013-11-18 23:29 static/image/common/back.gif
添加以下语句看看:

#include "stdafx.h"

没有作用。。。

yuqiuwangzi 发表于 2013-11-19 00:12:40

friendan 发表于 2013-11-18 23:29 static/image/common/back.gif
添加以下语句看看:

#include "stdafx.h"

之前写任何C程序都没问题,只是最近学数据结构,敲这些程序就一直出错,但是VC++6.0都是可以编译通过的。。。

friendan 发表于 2013-11-19 11:32:58

yuqiuwangzi 发表于 2013-11-19 00:12 static/image/common/back.gif
之前写任何C程序都没问题,只是最近学数据结构,敲这些程序就一直出错,但是VC++6.0都是可以编译通过的。 ...

这样的话,要么是VS2010设置错误,如lib路径,包含文件路径,bin路径等。
要么你得重新安装VS2010了。

yuqiuwangzi 发表于 2013-11-19 12:51:01

friendan 发表于 2013-11-19 11:32 static/image/common/back.gif
这样的话,要么是VS2010设置错误,如lib路径,包含文件路径,bin路径等。
要么你得重新安装VS2010了。

我不知道怎样就算设置正确了。。。我先重装试试看
页: [1]
查看完整版本: VS2010编译不了VC6的代码