c - 无法列出堆栈
问题描述
我正在尝试将推送、弹出和列表功能放入堆栈。它应该首先推送 4 个字符串(我将它们写为数组,因为 %s 无法正常运行),然后弹出 3 个字符串,并列出最后一个字符串。但是,代码无法正常运行。有人可以帮助我吗?
这是代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include<conio.h>
#define MAX 4
int point = -1;
char item[MAX][20];
void push(char item[point])
{
point++;
};
void pop(char item[point])
{
point--;
};
void list()
{
if (point > -1) {
for (int i = 0; i <= point; i++) {
printf("%c\n", item[point-i]);
}
}
};
int main()
{
//AB01
char arrA[4] = {'A','B','0','1'};
for(int i=0;i<4;i++)
{
printf("%c",arrA[i]);
}
point++;
printf("\n");
push (arrA[4]);
//AB02
char arrB[4] = {'A','B','0','2'};
for(int i=0;i<4;i++)
{
printf("%c",arrB[i]);
}
point++;
push (arrB[4]);
printf("\n");
//AB03
char arrC[4] = {'A','B','0','3'};
for(int i=0;i<4;i++)
{
printf("%c",arrC[i]);
}
point++;
push (arrC[4]);
printf("\n");
//AB04
char arrD[4] = {'A','B','0','4'};
for(int i=0;i<4;i++)
{
printf("%c",arrD[i]);
}
point++;
push (arrD[4]);
printf("\n");
//Delete 3 strings
pop(arrA[point]);
pop(arrB[point]);
pop(arrC[point]);
list();
return 0;
}
似乎list
无法正常运行。因为我使用数组来显示字符串,这让我无法正确列出(因为我在 中再次使用了一个数组list()
,然后它变成了 2 个数组)。如果我想让我的字符串(数组中的字符)被列出,我该怎么办?
解决方案
推荐阅读
- azure-data-factory - 数据流计算与 Databricks 的不同之处
- pandas - 如何通过 pandas 从具有两列日期的文件中导入数据?
- javascript - mongooseDB 搜索/过滤不参考架构的数据
- c# - 将 System.Net.HttpWebRequest TransferEncoding 设置为 chunked 总是会导致异常
- mongodb - 如何仅获取不包含在另一条记录的数组中的记录
- angular - bsDatepicker 为 endDate 设置 minDate
- python - 显示值的条形图 -Seaborn 或 plt
- xamarin - vs2019+vs2022 避免在 Xamarin.Essentials.FeatureNotSupportedException 上中断
- java - Azure SQL 处理特殊字符
- asp.net-core - 如何使用 serilog 将异常记录到 appinsights?