首页 > 解决方案 > 读取时出现分段错误

问题描述

为什么我在这里遇到分段错误?我需要编写一个程序,在该程序中,我需要使用系统调用以相反的顺序打印行。

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;
  }

标签: csegmentation-faultsystem-calls

解决方案


推荐阅读