C Don';我不知道我是否';我用错误的方式复制这些整数,但是我';我犯了一些奇怪的错误

C Don';我不知道我是否';我用错误的方式复制这些整数,但是我';我犯了一些奇怪的错误,c,shell,C,Shell,我得到了以下错误,希望有人能为我解释这些错误,因为我目前C语言不是很好 case ' ': This is the error here. shellNew.c:57: error: a label can only be part of a statement and a declaration is not a statement int rCheck = 0; shellNew.c:58: error: expected expression b

我得到了以下错误,希望有人能为我解释这些错误,因为我目前C语言不是很好

case ' ':     
This is the error here. shellNew.c:57: error: a label can only be part of a statement and                 a declaration is not a statement

int rCheck = 0;
shellNew.c:58: error: expected expression before â

int foundPos = 0;
while(rCheck < 10)
{
  if(inputBuffer[2] == historyBuffer[rCheck][0])
  {
shellNew.c:63: error: â undeclared (first use in this function)
shellNew.c:63: error: (Each undeclared identifier is reported only once
shellNew.c:63: error: for each function it appears in.)

  foundPos = rCheck;
  }
rCheck++;
}
if(rCheck == 0)
{
  printf("There was no command matching your criteria\n");
}
else
{
  strcpy(inputBuffer, historyBuffer[rCheck]);
}
break;
案例“”:
这就是这里的错误。shellNew.c:57:错误:标签只能是语句的一部分,而声明不是语句
int-rCheck=0;
c:58:error:before–之前应为表达式
int foundPos=0;
而(rCheck<10)
{
if(inputBuffer[2]==historyBuffer[rCheck][0])
{
c:63:error:1–未声明(此函数首次使用)
c:63:error:(每个未声明的标识符只报告一次
shellNew.c:63:错误:对于它出现在中的每个函数。)
foundPos=rCheck;
}
rCheck++;
}
如果(rCheck==0)
{
printf(“没有与您的条件匹配的命令\n”);
}
其他的
{
strcpy(输入缓冲区,历史缓冲区[rCheck]);
}
打破

假设在前面的56行代码中有一个
开关,那么编译器会抱怨您不能执行以下操作:

switch (variable)
{
case ' ':
    int var = 23;
因为声明不算作语句,必须将标签附加到语句。转换成一个很小的函数,这段代码给出了您在Mac OS X 10.7.5上使用GCC 4.7.1报告的错误。随后出现的错误可能是因为变量
rCheck
没有声明,因为标签放错了位置,导致在尝试使用时出现问题

不能跳过变量声明,因此需要在
开关
语句块内使用语句块:

switch (variable)
{
case ' ':
    {
    int var = 23;
    ...
    }
    break;
}

这段代码编译得很干净。将
break
放在语句块内还是放在语句块外,这是一个有待讨论的问题;它们是等效的。

可能会报告第一个错误,因为您的代码以事例“”开头:这在switch语句之外是不合法的。之所以有–字符,是因为gcc喜欢使用xterm不喜欢的一些时髦的反引号字符。使用另一个终端程序(或者可能是新版本的xterm?)查看完整的错误消息。如果您没有使用xterm,那么您使用的任何字符都不喜欢这些字符。我怀疑重音字符是由于GCC在输出中产生了有趣的字符,而复制/粘贴没有很好地处理它们。我有时会遇到这个问题。你能按原样发布完整的代码吗?