c - 读取时出现分段错误
问题描述
为什么我在这里遇到分段错误?我需要编写一个程序,在该程序中,我需要使用系统调用以相反的顺序打印行。
struct Stack {
int top;
char a[MAX];
};
int main() {
struct Stack * st;
st -> top = -1;
char ch;
int strings = 0;
while (read(0, &ch, 1) > 0) {
//push(st,ch);
if (ch == '\n') // segmentation fault
++strings;
}
解决方案
推荐阅读
- python - 如何使用 python-telegram-bot 将联系人的电话号码存储在 ChatBot 的内存中
- java - JDK8:“java.lang.NoClassDefFoundError:javax/xml/ws/Service”
- python - 什么是数据类型 LOB 的列不能是唯一的或主键错误?
- python - 如何从 django 获取所有当前会话?
- java - 添加到请求 DTO 时收到 415 错误消息
- azure-devops - 仅允许特定 AD 组下的用户批准 Azure DevOps 上的拉取请求
- python - 当我尝试加入/合并/定位时,熊猫与初始索引不匹配
- python - 如何使用 OpenCV 将文件保存在正确编号的目录中
- neural-network - 在神经网络中,隐藏的加权输入和偏置的形状可以不同吗?
- hadoop - Hadoop:如何从外部 IP 访问 HDFS?