小编Iam*_*ent的帖子

警告:ISO C禁止空翻译单元

在头文件中,我有以下代码,它在尝试链接时给出了标题中的错误.

#ifndef BOOLEAN_H
#define BOOLEAN_H

#ifndef FALSE
#define FALSE 0
#endif

#ifndef TRUE
#define TRUE !FALSE
#endif

#endif

indicating the error occurs in the line of the last #endif 
Run Code Online (Sandbox Code Playgroud)

c macros

8
推荐指数
1
解决办法
1万
查看次数

在C编程中定义并初始化此数据类型

有人能告诉我这是否是这个数据类型的正确定义,以及我初始化它的方式是否正确?

typedef int const * (* const DataOne)(const int *);
Run Code Online (Sandbox Code Playgroud)

=>上面的数据类型显示了一个指向函数的常量指针,该函数将指向常量的指针int作为参数并返回指向常量的指针int.

=>初始化和声明: DataOne = &myFunction(7);

c typedef function-pointers

3
推荐指数
1
解决办法
89
查看次数

C编程中的结构

我正在尝试读取文件内容并将其存储到结构中,因为某些原因我不断收到分段错误.请帮助我,我也不了解valgrind.

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

typedef struct {
    int day;
    int month;
    int year;
    char text[401];
} journal;

int main(int argc, char** argv){
    int  i, numberEntries;
    FILE* fp = fopen(argv[1], "r");

    fscanf(fp,"%d", &numberEntries); /* reads value on first line of file for number of entries */
    printf("%d", numberEntries); /* check that it worked */
    journal *entryArray ;
    entryArray = (journal*)malloc(sizeof(journal));

    if(fp == NULL){
        perror("Error opening file");
    } else {

        for(i=0; i<4; i++){
            fscanf(fp,"%d/%d/%d", entryArray[i].day, entryArray[i].month, entryArray[i].year);
            fgets(entryArray[i].text, 400, fp);
            printf("%s", …
Run Code Online (Sandbox Code Playgroud)

c struct

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

标签 统计

c ×3

function-pointers ×1

macros ×1

struct ×1

typedef ×1