C
C. Sengstock
Hi,
i want to save the keywords of an ini file in a struct, together with a
fpos_t. I think i´m right with the concept, but the access through fsetpos()
doesn´t work. The position is always wrong (except, in this example, the
first line).
My struct looks like this:
***
typedef struct {
char pname[32];
fpos_t pos;
} iniParam;
This routine reads the data and put it to "iniParam param[100]":
***
while (!feof (pFile)) {
fgetpos(pFile, &pos);
c=fgetc(pFile);
ungetc(c, pFile);
if(c == '#')
fgets (linebuf, 255, pFile);
else {
param.pos = pos;
fgets (linebuf, 255, pFile);
sscanf(linebuf, "%s", param.pname);
i++;
}
}
This routine reads the keywords and do a corresponding fscanf:
***
for(i=0; i<n; i++) {
if(strcmp(param.pname, "keyword1") == 0) {
pos = param.pos;
fsetpos(pFile, &pos);
fscanf(pFile, "%*s %d", ¶m1);
}
if(strcmp(param.pname, "keyword2") == 0) {
...
Don´t know why the access through a fpos_t position doesn´t work.
Thanks for any help, Chris
i want to save the keywords of an ini file in a struct, together with a
fpos_t. I think i´m right with the concept, but the access through fsetpos()
doesn´t work. The position is always wrong (except, in this example, the
first line).
My struct looks like this:
***
typedef struct {
char pname[32];
fpos_t pos;
} iniParam;
This routine reads the data and put it to "iniParam param[100]":
***
while (!feof (pFile)) {
fgetpos(pFile, &pos);
c=fgetc(pFile);
ungetc(c, pFile);
if(c == '#')
fgets (linebuf, 255, pFile);
else {
param.pos = pos;
fgets (linebuf, 255, pFile);
sscanf(linebuf, "%s", param.pname);
i++;
}
}
This routine reads the keywords and do a corresponding fscanf:
***
for(i=0; i<n; i++) {
if(strcmp(param.pname, "keyword1") == 0) {
pos = param.pos;
fsetpos(pFile, &pos);
fscanf(pFile, "%*s %d", ¶m1);
}
if(strcmp(param.pname, "keyword2") == 0) {
...
Don´t know why the access through a fpos_t position doesn´t work.
Thanks for any help, Chris