我收到错误推送并在堆栈中弹出 [英] I'm getting an error push and pop in the stack

查看:64
本文介绍了我收到错误推送并在堆栈中弹出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了这个程序,显示你在堆栈中推送和弹出。我在标有评论的行上收到错误

I wrote this program that shows you push and pop in the stack. I'm getting an error on the line I've marked with a comment

prog.cpp:23:69: warning: missing terminating ' character
         printf("The element is %d\n",a[6]); >>>>>>>>>>>>>>>>it doesn't work here the same in the upper fn
                                                                     ^
prog.cpp:23:9: error: missing terminating ' character
         printf("The element is %d\n",a[6]); >>>>>>>>>>>>>>>>it doesn't work here the same in the upper fn
         ^
prog.cpp:3:1: error: expected unqualified-id before '>>' token
 >>>>>>this is the a program that show you the push and pop in the stack <<<<<<<<<<<<<<<<<<<<<<<
 ^





我尝试了什么:





What I have tried:

#include<stdio.h>

>>>>>>this is the a program that show you the push and pop in the stack <<<<<<<<<<<<<<<<<<<<<<<<br mode="hold" />void push(int a[],int size)
{
    int i;
    printf("enter the elements in the array");
    for(i=0;i<size;i++)>
    {
        printf("the element of the location :%d is :%d",i,a[i]);
        if(i==size)
           printf("The stack is full");
    }
}
void pop(int a[],int sizea)
{
    int j;

    for(j=sizea;j>0;j--)
    {

        printf("the location is %d",j);
        printf("The element is %d\n",a[j]); >>>>>>>>>>>>>>>>it doesn't work here the same in the upper fn
        if(j==1)
            printf("The stack is empty");
    }
}

int main()
{
    int x,y,a[6]={1,2,3,4,5,6};

    printf("push=1;pop=2\nchoose one of them: ");
    scanf("%d",&x);
    y=sizeof(a)/sizeof(int);

    if(x==1)
    {

    printf("welcome in push");
    push(a[6],6);

    }

    if(x==2)
    {
        printf("welcome in pop");
        pop(a[6],y);
    }

    return 0;
}

推荐答案

您收到错误消息,因为 a [6] 是一个整数,数组是 a



对于代码中的其他问题:

您应该学习尽快使用调试器。而不是猜测你的代码在做什么,现在是时候看到你的代码执行并确保它完成你期望的。



调试器允许你跟踪执行逐行检查变量,你会看到它有一个停止做你期望的点。

调试器 - 维基百科,免费的百科全书 [ ^ ]

掌握Visual Studio 2010中的调试 - A初学者指南 [ ^ ]



调试器在这里向您展示您的代码正在做什么,您的任务是与它应该做什么进行比较。 />
当代码不做ex的时候你接近一个bug。



建议:你应该正确学习语法。

顺便说一句,这个程序与堆栈无关。
You get the error message because a[6] is an integer, the array is a

For the other problems in your code:
You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
When the code don't do what is expected, you are close to a bug.

Advice: You should learn the syntax properly, really.
By the way, this program have nothing to do with a stack.


这篇关于我收到错误推送并在堆栈中弹出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆