On Wed, 8 Oct 2003 03:26:26 +0200, "C. Sengstock" <>
wrote:
>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).
It works for me with just two problems. The reading loop doesn't
detect end of file correctly as explained in the faq:
http://www.eskimo.com/~scs/C-faq/q12.2.html
Also blank lines and junk lines in the ini file result in invalid
entries in param[].
My advice is:
1. Check the return code of each library functions you call.
2. Post a complete but minimalist program, including the ini
file contents that demonstrate the problem.
>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[i].pos = pos;
> fgets (linebuf, 255, pFile);
> sscanf(linebuf, "%s", param[i].pname);
> i++;
> }
>}
>
>This routine reads the keywords and do a corresponding fscanf:
>***
>for(i=0; i<n; i++) {
> if(strcmp(param[i].pname, "keyword1") == 0) {
> pos = param[i].pos;
> fsetpos(pFile, &pos);
> fscanf(pFile, "%*s %d", ¶m1);
> }
> if(strcmp(param[i].pname, "keyword2") == 0) {
> ...
>
>Donīt know why the access through a fpos_t position doesnīt work.
>Thanks for any help, Chris
Nick.