简体   繁体   English

指向C中的结构-错误:“ *”标记之前的预期“)”

[英]Pointing to struct in C - error: expected ')' before '*' token

I am trying to compile this code (gonna be a simulation of Langton's Ant): 我正在尝试编译以下代码(将模拟兰顿的蚂蚁):

    #include <conio.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>

    typedef struct
    {
        unsigned short x, y;
        enum directions {up = 0, right, down, left} direction;
    } langtonsAnt;

    void turnAnt (lantonsAnt *pant, unsigned short quarterTurns)
    {
        pant->direction = (pant->direction + quarterTurns) % 4;
    }

    int main ()
    {
        return EXIT_SUCCESS;
    }

However, I keep getting this error: 但是,我不断收到此错误:

12|error: expected ')' before '*' token| 12 |错误:预期在'*'标记之前的')'|

The compiler is gcc. 编译器是gcc。

I cannot figure out what's wrong as I already searched the web and various references. 我已经搜索了网络和各种参考文献,因此无法弄清出什么问题了。

PS Don't worry about the headers, those are needed elsewhere in the program. PS不用担心标题,程序中其他地方都需要这些标题。

void turnAnt (lantonsAnt *pant, unsigned short quarterTurns)

应该

void turnAnt (langtonsAnt *pant, unsigned short quarterTurns)

You are missing a 'g' in your passed pointer to the function turnAnt! 您在指向函数turnAnt的传递指针中缺少“ g”! Notice the 'g' after "lan" in the struct name? 注意结构名称中“ lan”之后的“ g”吗?

typedef struct
    {
        unsigned short x, y;
        enum directions {up = 0, right, down, left} direction;
    } langtonsAnt;

But then in your function turnAnt, " lantonsAnt *pant " is missing the 'g'! 但是在您的函数turnAnt中,“ lantonsAnt * pant”缺少了“ g”! It should look like this: 它看起来应该像这样:

void turnAnt (langtonsAnt *pant, unsigned short quarterTurns)
{
    ......

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C Global Struct:“错误:&#39;{&#39;令牌之前的预期表达式” - C Global Struct: “error: expected expression before '{' token” C-创建和使用结构数组? 错误:预期标识符或&#39;[&#39;标记前的&#39;(&#39; - C - Creating and using an struct array? error: expected identifier or '(' before '[' token 错误:在“*”标记结构之前应有“{”(C 编程帮助) - error: expected ‘{’ before ‘*’ token struct (C programming help) 错误:结构中&#39;=&#39;标记之前的预期&#39;:&#39;,&#39;,&#39;,&#39;;&#39;,&#39;}&#39;或&#39;__attribute__&#39; - error: expected ‘:’, ‘,’, ‘;’, ‘}’ or ‘__attribute__’ before ‘=’ token in struct C错误:在&#39;...&#39;标记之前预期&#39;;&#39;,&#39;,&#39;或&#39;)&#39; - C error: expected ';', ',' or ')' before '…' token C中“ *”令牌错误之前的预期“)” - expected ')' before '*' token error in c C错误:在&#39;=&#39;标记前应为&#39;;&#39;,&#39;,&#39;或&#39;)&#39; - C -error: expected ';', ',' or ')' before '=' token C:错误:预期&#39;)&#39;之前&#39;;&#39; 代币 - C: error: expected ')' before ';' token 如何使用结构 || 在 C 中创建一个 NULL(s) 的 2D char* 数组错误:“{”标记之前的预期表达式 - How to make a 2D char* array with NULL(s) in C with a struct || error: expected expression before '{' token 出现错误:在尝试验证结构时,C 中“{”标记之前的预期表达式 - Getting error: expected expression before ‘{’ token in C while trying to verify struct
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM