www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/05/01/23:08:32

Message-ID: <20000502033204.98303.qmail@hotmail.com>
X-Originating-IP: [165.91.71.145]
From: "Sxott b." <sxotty AT hotmail DOT com>
To: djgpp AT delorie DOT com
Subject: reading text files
Date: Tue, 02 May 2000 03:32:04 GMT
Mime-Version: 1.0
Reply-To: djgpp AT delorie DOT com

I want to read 2 values from a text file, modify them and write them back.  
I placed them alone on a line each so the file looked like this

12
45


that was all, but I couldn't figure out how, so I wrote the text file as

a12
c45

that way I could search for a and take the number following, and likewise 
with c, but none of these things worked, is there a way to do this?  how 
would I go about it thanks.
if ((fp = fopen("c:\\text.txt","rt")) == NULL)
  {
    printf("Error opening file text.txt\n");
  }
  if(write!=1)
  {
  //here is the place to read in added and counted
       //dos_read  fread(added_int,size?,1,fp); these are wrong
       //fread(counted_int,size?,1,fp);
        for(i=0;(c=fgetc(fp))!=EOF&&i<1000;++i)
          data[i]=(char)c;
       for(c=0;c<i;++c)
         if(data[c]=='a'){added_int=data[c+1];}
         if(data[c]=='c'){counted_int=data[c+1];}
  }
fclose(fp);
________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019