如何访问C中的结构中的变量进行打印?

时间:2016-05-13 19:11:49

标签: c struct

**指有没有办法访问来自其他结构的变量?当

  

我尝试此代码,我收到此编译错误。   **      test.c:在函数'readRecordsFromFile'中:        test.c:70:18:错误:'kdnode'之前的预期表达式           printf(“%f \ n”,kdnode.data.latitude);

#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
#include <math.h>
#define rec_size 112
typedef struct _Node kdnode;
typedef struct _Record record;

static void readRecordsFromFile(char *filename);
struct _Record{
    int plateNumber;
    long *name[32];
    double area;
    int population;
    int density;
    int popcitycenter;
    long region;
    double latitude;
    double longtitude; 
};
struct _Node
    {
        //kdnode left;
        //kdnode right;
        record data;
        bool type;
        double x;
        double y;
        int pagenumber; 
    };
    int main(){
    readRecordsFromFile("data.dat");
        return 0;
    }

    static void readRecordsFromFile(char *filename)
    {
        FILE* inputFile;
        inputFile = fopen(filename, "rb");
        int i;
        if(!inputFile) {
        printf("Could not open file");
        return;
    }
        int length,record_count;
        fseek(inputFile,0,SEEK_END);
        length=ftell(inputFile);
        fseek(inputFile,0,SEEK_SET);
        record_count = length/sizeof(record);
        kdnode kd;
        fread(&kd,rec_size,2,inputFile);
        printf("%d",ftell(inputFile));
        for (i = 0; i < record_count; i++)
        {
        printf(" %f\n",kdnode.data.latitude);
        }
            fclose(inputFile);
    }

1 个答案:

答案 0 :(得分:4)

select DATEDIFF(second, EventStartTimeStamp_UTC0, EventEndTimeStamp_UTC0) as EventDuration from allEvent where ABS(DATEDIFF(Minute, EventStartTimeStamp_UTC0, EventEndTimeStamp_UTC0)) < 1 typedef struct _Nodetypedefknode表示数据类型,它不是标识符,因此

knode

必须是

printf(" %f\n",kdnode.data.latitude);

您还应该检查printf(" %f\n", kd.data.latitude); 等函数的返回值。