错误:标签只能是声明的一部分

Jos*_*ges 5 c gcc pointers compiler-errors getchar

我正在用C语言编写一个brainfuck解释器,我在使用一些我不习惯的东西时遇到了一些麻烦.在brainfuck中,逗号(,)本质上是getchar().所以我有以下代码:

//This is just ptr
static char *ptr;

switch (command)
{
  case ',':
    *ptr=getchar(); // Here's the code causing error
    break;
}
Run Code Online (Sandbox Code Playgroud)

error: a label can only be part of a statement and a declaration is not a statement当我尝试编译时,gcc会抛向我.

有任何想法吗?(对不起,不太熟悉这个错误)

bit*_*ask 7

我相信你的意思

*ptr = getchar();
Run Code Online (Sandbox Code Playgroud)

代替

ptr*=getchar();
Run Code Online (Sandbox Code Playgroud)

因为*=平均值将左侧的值乘以右侧的值,并将其赋值给左侧值.但是,您要取消引用 ptr并将结果写入该getchar位置.


除此之外,你的代码与我的gcc版本完全匹配(如果我在command某处声明),所以你显然没有向我们展示一个完整的例子.