Of course there is. Say something like
facit[arrayIndex + sizeof(double) * matchIndex] = strtod(token, NULL);
I take no validity for the code, however. But that's how you write to an array.
Thanks, but I don't think that's it. I would like to replace...
...with a one liner, if it's possible.Code:if (!matchIndex) ptr = &matchArray[arrayIndex].home; else if (matchIndex == 1) ptr = &matchArray[arrayIndex].draw; else ptr = &matchArray[arrayIndex].away; *ptr = strtod(token, NULL);
OrCode:/*.... */ double *a[] = { &matchArray[arrayIndex].home , &matchArray[arrayIndex].draw, &matchArray[arrayIndex].away }; // grrrr wtf is wrong with i ,j , k???? for (matchIndex = 0; matchIndex < 3; matchIndex ++) { if (!strIsFloat(token)) { error(1, 0, "datafile parsing error -- expected float"); } *a[matchIndex] = strtod(token, NULL); token = strtok(NULL, " "); } /* .... */
Code:double a[3]; for (matchIndex = 0; matchIndex < 3; matchIndex ++) { if (!strIsFloat(token)) { error(1, 0, "datafile parsing error -- expected float"); } a[matchIndex] = strtod(token, NULL); token = strtok(NULL, " "); } matchArray[arrayIndex] = (match_t) { a[0] , a[1], a[2] }; // C99 feature. or assign to each member....
Last edited by Bayint Naung; 08-31-2010 at 01:29 AM.
That's one nice solution. Thanks...
He, he, he... Nothing's wrong with it. My lousy brain just have a hard time cope with it. I leave the code for six moths, and when I come back, I'm totally lost. Sure having trouble to keep i, j and k apart, not knowing which one of the totally meaningless variable names holding what value. I've done it too many times. This way, I'm back in a couple of seconds.
What I ain't got in my brains, I've got to put in my fingers.