小编Per*_*lah的帖子

C语法错误:缺少';' 在'类型'之前

我在Microsoft Visual C++ 2010 Express中正在进行的C项目中遇到一个非常奇怪的语法错误.我有以下代码:

void LoadValues(char *s, Matrix *m){
    m->columns = numColumns(s);
    m->rows = numRows(s);
    m->data = (double*)malloc(sizeof(double) * (m->rows * m->columns));
    int counter = 0;
    double temp;
    bool decimal;
    int numDec;
    while(*s != '\0'){
        .
        .
        .
    }
}
Run Code Online (Sandbox Code Playgroud)

当我尝试构建解决方案时,我得到了"缺失"; 在为所有变量(temp,counter等)输入"error"之前,并尝试在while循环中使用它们中的任何一个会导致"未声明的标识符"错误.我确保通过这样做来定义bool

#ifndef bool
    #define bool char
    #define false ((bool)0)
    #define true ((bool)1)
#endif
Run Code Online (Sandbox Code Playgroud)

在.c文件的顶部.我搜索了Stack Overflow的答案,有人说旧的C编译器不允许你在同一个块中声明和初始化变量,但我认为这不是问题,因为当我注释掉这些行时

m->columns = numColumns(s);
m->rows = numRows(s);
m->data = (double*)malloc(sizeof(double) * (m->rows * m->columns));
Run Code Online (Sandbox Code Playgroud)

所有的语法错误消失了,我不明白为什么.任何帮助表示赞赏.

---编辑----请求Matrix的代码

typedef struct {
    int rows;
    int columns;
    double …
Run Code Online (Sandbox Code Playgroud)

c syntax-error visual-c++-2010

2
推荐指数
1
解决办法
1336
查看次数

包含time.h的C中的问题?

我正在处理这个名为timeKeeper.h(和.c)的大型项目中的文件

--------------编辑---------------修复了那些仍然被破坏的人------------- -

#ifndef TIMEKEEPER_H_
#define TIMEKEEPER_H_

#include <time.h>
#include <stdbool.h>

bool isAfter(time_t time);
void setTime(char seconds, char minutes, char hours, char day,
        char month, char year);
    void tickSeconds(void);
time_t getCurrentTime(void);
time_t createTime(char seconds, char minutes, char hours, char day,
        char month, char year);
void startTime(void);
time_t addSeconds(int seconds, time_t time);
long timeRemaining(time_t time);
void rtc_set(char seconds, char minutes, char hours, char days, char months,
    char year);
 #endif
Run Code Online (Sandbox Code Playgroud)

当我尝试构建我的项目时,此文件中有一堆错误(以及任何使用time.h的文件).以下是timeKeeper.h中的一些错误:

expected ')' before 'time'        Line 6
expected '"', ',', ';','asm', or …
Run Code Online (Sandbox Code Playgroud)

c time.h atmel

-2
推荐指数
1
解决办法
3784
查看次数

标签 统计

c ×2

atmel ×1

syntax-error ×1

time.h ×1

visual-c++-2010 ×1