大量的语法错误

时间:2011-11-21 08:57:40

标签: c

我试图用C和SDL创建一个小游戏,以有趣的方式开始使用SDL。我会在我的主游戏循环中使用我的Timer结构和函数来粘贴fps。但我得到了很多“错误C2054:预期”('跟随't'“,总共约25个错误。

这是:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "SDL.h"

struct Timer {

    int startTicks;
    int pausedTicks;

    int paused;
    int started;

};

void Init( Timer *t )
{
    t->startTicks = 0;
    t->pausedTicks = 0;
    t->paused = 0;
    t->started = 0;
}

void StartTimer( Timer *t )
{
    t->started = 1;
    t->paused = 0;

    t->startTicks = SDL_GetTicks();
}

void StopTimer( Timer *t )
{
    t->started = 0;

    t->paused = 0;
}

void PauseTimer( Timer *t )
{
    if( t->started == 1 && t->paused == 0 )
    {
        t->paused = 1;
        t->pausedTicks = SDL_GetTicks() - t->startTicks;
    }
}

void UnpauseTimer( Timer *t )
{
    if( t->paused == 1 )
    {
        t->paused = 0;
        t->startTicks = SDL_GetTicks() - t->pausedTicks;

        t->pausedTicks = 0;
    }
}

int GetTicks( Timer *t )
{
    if( t->started == 1 )
    {
        return t->pausedTicks;
    }
    else
    {
        return SDL_GetTicks() - t->startTicks;
    }

    return 0;
}

这里有什么不对?提前谢谢!

3 个答案:

答案 0 :(得分:4)

所有t个变量都应该是struct Timer类型,而不是Timer

或者,或者,将其定义为:

typedef struct sTimer {
    int startTicks;
    int pausedTicks;
    int paused;
    int started;
} Timer;

使Timer成为“头等”类型。

答案 1 :(得分:1)

在C中,你需要这样做:

struct Foo
{
    ...
};

...

void bar(struct Foo *p);
           ^

或者这个:

typedef struct Foo
{  ^
    ...
} Foo;
   ^
...

void bar(Foo *p);

[我更喜欢第二个版本;它节省了必须在整个地方写struct。]

答案 2 :(得分:1)

查找第一个错误并从中开始工作。通常,其他许多是第一个的结果。