Ben
Ben

Reputation: 362

C- error expected identifier or '(' before '.' token

I'm working on a gps project using gpx files, the code is in c and i have a struct called Splitdata:

// Node Structure for storing Splits Data
typedef struct SplitData {
    double selevation[100];
    double pace[100];
    int splitnumber[100];
    int mins[100];
    int secs[100];
}data;

i then try to reference that struct in this function:

double calculate_tot_dist(struct node *lh){
    double lat1 = 0, lon1 = 0;
    double pathLen = 0;
    struct node *ptr = lh;
    double averagePace = 0;
    double elevationchange = 0;
    int kilocounter = 1;
    int i =0;


    struct timeStr tm1,tm2;


    strcpy(startTimeStr, lh->timeString);

    while(ptr != NULL){
        if (lat1 == 0){
            // First node
            lat1 = ptr->lat;
            lon1 = ptr->lon;
            elevationchange = ptr->elevation;
             ptr = ptr->next;

        }else
        {
            pathLen += haversine_m(lat1, lon1, ptr->lat, ptr->lon);

            if (((int)pathLen / 1000) > kilocounter)
             {
             // printf("%d", split->splitnumber[i]);
            data.splitnumber[i] = kilocounter; 
            data.selevation[i] = ptr->elevation;
            kilocounter++;
            i++;
              }
            lat1 = ptr->lat;
            lon1 = ptr->lon;
            elevationchange = ptr->elevation;
            ptr = ptr->next;
        }


    }

When i attempt to compile the code i get an error saying: C- error expected identifier or '(' before '.' token

the error is being reported for lines:

data.splitnumber[i] = kilocounter; 
 data.selevation[i] = ptr->elevation;

Can anyone see why this would be the case? thanks

Upvotes: 0

Views: 7405

Answers (1)

e9_
e9_

Reputation: 174

in this case 'data' is not a variable but a type SplitData (for explanation refer to http://en.wikipedia.org/wiki/Typedef). If you want 'data' to be a variable then you could do following modification:

// Node Structure for storing Splits Data
typedef struct SplitData {
    double selevation[100];
    double pace[100];
    int splitnumber[100];
    int mins[100];
    int secs[100];
};

SplitData data;

or define another variable called data in the scope of the calculate_tot_dist() function

(for reference I made your code compile here https://coderpad.io/968894)

Upvotes: 2

Related Questions