C 错误:令牌之前'['预期为非限定 id
C Error:expected unqualified-id before '[' token
我想编写一个可以在句子中获取每个不同字符的程序。但是当我使用GCC编译代码时,它显示出这样的错误: error ::预期'[''token。之前的未合格的ID,这些错误发生在这些行中:
CountMachine[cnt].ch=*(S.ch);
CountMachine[cnt].count++;
if(*(S.ch)==CountMachine[j].ch)
.....
(where I use CountMachine[]).
这是我的完整代码:
Count Char.h:
typedef struct
{
char ch;
int count=0;
}CountMachine[50];
typedef struct
{
char *ch;
int length;
}HString;
Count Char.cpp(但我使用C的语法(
void CountChar(HString S)
{
int cnt=0;
for(int i=0;i<S.length;i++)
{
if(i==0)
{
CountMachine[cnt].ch=*(S.ch);
CountMachine[cnt].count++;
cnt++;
S.ch++;
}
else
{
for(int j=0;j<cnt;j++)
{
if(*(S.ch)==CountMachine[j].ch)
{
CountMachine[j].count++;
S.ch++;
break;
}
if(j==cnt-1)
{
CountMachine[cnt].ch=*(S.ch);
CountMachine[cnt].count++;
cnt++;
S.ch++;
}
}
}
}
printf("There are %d different characters.n",cnt-1);
for(int m=0;m<cnt-1;m++)
{
printf("the number of character %c is %d",CountMachine[m].ch,CountMachine[m].count);
}
}
您将CountMachine
声明为一种类型,其中包括50个结构,其中包含一个字符和整数CountChar.h
中,然后您在CountChar.cpp
中处理类型本身。
您无法在类型中解决特定项目,您需要创建类型CountMachine
的变量,或从标题中的CountMachine
声明中删除关键字typedef
。
您有一个非常精美的类型别名,该别名声明CountMachine
类型,而不是包含50个未命名结构数组的变量。
typedef struct
{
char ch;
int count=0;
}CountMachine[50];
// CountMachine is a type (array 50 of unnamed struct)
// step-by step declaration is much more clear:
struct machine
{
char ch;
int count=0;
};
typedef struct machine machine_t;
machine_t machines[50];
// machines is a variable that holds an array of 50 machine_t
相关文章:
- 我不断收到 [错误] ID 返回 1 退出状态错误,但看不到问题所在
- 方法内部但循环仍得到预期的不合格id错误C++
- Xcode 9.4.1 中的 Apple Mach-O 链接器 (id) 错误
- 错误:令牌 { '{' 之前应存在非限定 ID
- DCMTK 了解"DIMSE 没有有效的演示上下文 ID"错误
- C++中的"expected unqualified-id"错误是什么?
- c++ for 循环中预期的非限定 id 错误
- 在"." 令牌之前应为非限定 ID(C++ 错误)
- 预期"{"错误?以及预期的未指定 ID 错误?
- 错误:预期的非限定 ID 错误:含义和修复
- 安卓-NDK-R7C "deque.h"中的非限定 ID 错误
- 预期的不合格id错误,很可能是原因
- 意外的非限定 ID 错误
- C++中类出现预期的不合格id错误
- 出现意外的非限定id错误
- iOS中出现不合格的id错误
- XSLT到HTML的转换.Qt5中的generate-id()错误
- 不合格的id错误和井字游戏板不工作
- 传递结构体数组的预期非限定id错误
- 如何执行项目范围内的唯一id /错误代码,以便在源代码中轻松找到错误的来源