Hi,
I posted the other day about a problem that i had regarding reading a header from a file and only taking out the words i need.
The header of this file is a group of words divided up by ";" characters and i have managed to read the line perfectly.
Now, these words are headers for the information below. Like a table of values.
What my problem is that i have to read the headers, remember the position of the ones i want (they could be in any sequence and theres 20 of them out of 40 headers in total).
finally, i want to use the "index" of the position of where they were found to identify where their information lies in the next line. The next lines are just floats seperated by ";" characters and thus have no identifiable marking.
This is a sample of the input file:
the problem is that (its very simple to solve, i guess) that the program refuses to cycle through all the components."RX_WEEK";"RX_TOM";"POS_TYPE";"SBAS_USED";"POS_FLA G";"NSV_USED";"NSV_LOCK";"MSK_USED";"MSK_LOCK";"NS _HPL";"NS_VPL";"NS_LAT";"NS_LON";"NS_ALT";"NS_DEW" ;"NS_DNS";"NS_DUP";"NS_DHOR";"NS_VE";"NS_VN";"NS_V U";"GPS_SEC";"NS_CLKBIAS";"NS_CLKDRIFT";"NS_X";"NS _Y";"NS_Z";"DOP_P";"DOP_G";"DOP_H";"DOP_V";"DOP_T" ;"RAIM_MODE";"RAIM_HPL";"RAIM_VPL";"NS_RES";"LOOP_ COUNT"
below is my attempt:
All help would be greatly appreciated, thanksCode:FILE* fp = fopen(posfilename, "a+"); { char *Elements[] = {"\"RX_WEEK\"", "\"RX_TOM\"", "\"SBAS_USED\"", "\"POS_FLAG\"", "\"NSV_USED\"", "\"NS_HPL\"", "\"NS_VPL\"", "\"NS_LAT\"", "\"NS_LON\"", "\"NS_ALT\"", "\"NS_DEW\"", "\"NS_DNS\"", "\"NS_DUP\"", "\"NS_DHOR\"", "\"GPS_SEC\"", "\"NS_RES\""}; //these are the values we are looking for char *TokenIndex[100]; char * Token; int k = 0; if (fgets( posinputbuff, BUFSIZ, fp ) != NULL ) // get the first line of the file (header) { printf ("Read line is %s \n\n", posinputbuff); // print to see we have the right line for (int b = 0; b < 40; b++) // to cycle through the whole header and get tokens { strcpy(copystring, posinputbuff); // copy string to prevent strtok errors Token = strtok (copystring, ";"); // take first value from the input header printf ("This Token is %s \n", Token); //print this token for (i = 0; i < 20; i++) { printf ("Element %i is %s \n\n", i, Elements[i]); // Print the value of the first element we are looking for if (strcmp(Token, Elements[i]) == '0') // compare the token and elemnt to see if they match { index = i; // if true then the first token is equal to the first element TokenIndex[k] = Elements[index]; printf ("Element %i in the final buffer is %s \n", index, TokenIndex[k]); k++; break; } break; } break; // break if to get next token } } }