Just my 2 cents;
This pulls your 2 values and every line from the file using fscanf and stores the values into
2 string arrays for manipulation, beware an overload if this file is large. Also in the fscanf \n starts the at the 2nd line in the
file. So you need 1 return on the first line, I did this at the beginning to avoid a NULL character from being read at the end.
You would then get an echo of the lasty line read into the array. <False values>
Fgets works good also.
With programs, it's your personal preference.


   if ( (stream = fopen(datafile, "r+")) == NULL)
   {
      printf("Could not open datafile \n");
   }
   else
   {
      while( !feof(stream))
      {
         fscanf(stream, "\n%[^:]:%[^\n]", &refname[i], &refvalue[i]);
         i++;
      }
   }
   fclose(stream);


This should help some, I use C programs to write CGI HTML's and found some quirke things happen in C.
But, have fun.




[EMAIL PROTECTED] wrote:
Hi,
        I'm working on a little project, and I
        got stuck on a problem.  So far, I
        already have interface, and the rest
        created, now, all I need, is a way to
        retrieve information from a file.

        A file will consist of

        <Field name>:<Value>
        <Field name>:<Value>

        the ":" in the middle is the separator,
        and <Value> can be either numbers or
        characters.
        I can figure it out, how to store the
        both variables once retrieved ( I plan on
        using struct ), all I need a sample on
        how to read the file, and retrieve both
        <Field> and <Value>

        Any advise?

Thank you very much,
Nikita.

P.s.  Does anybody know of a program I can
use as an example ( with source, of course ).

 
begin:          vcard
fn:             Michael Ferrini
n:              Ferrini;Michael
org:            Is - Telecom Division
adr:            ;;;Westwood;MA;;USA
email;internet: [EMAIL PROTECTED]
title:          IS Software Programmer/Analyst
tel;work:       X5084
x-mozilla-cpt:  ;0
x-mozilla-html: TRUE
version:        2.1
end:            vcard

Reply via email to