Author Topic: operartion i/o with two sequential file  (Read 252 times)

0 Members and 1 Guest are viewing this topic.

monliv

  • Newbie
  • *
  • Posts: 17
    • View Profile
operartion i/o with two sequential file
« on: June 01, 2023, 01:10:27 PM »
Hey Jean
I need Help for operation with two sequential files not .db
if is possible...
I looked for examples but couldn't find anything.
this is the example:

char temp[256],name[61],nameo[61];
strset(if1, "%sdb\in.txt",home);`input only
strset(of1, "%sdb\out.txt",home);`i/o
deletefile(of1);
while (TRUE = lineread(if1, tmp))               `read the 1 file
      { substr(tmp, 0, 60,name);           `I have the key to the file
     
      while (TRUE = lineread(of1, tmp))         `read the 2 file
        { substr(tmp, 0, 60,nameo);             `I'm going to check the second file if it's already there
          if (strcmp(name, nomeo) = 1) continue;`already present in the second file I do not add
        }
      linewrite(of1, name);                     ` write on 2 file I add   
      continue;}

read if1,ceck exist on of1,if yes, skip else write on of1.
so not create duplicate files !?!

Jean

  • Administrator
  • Hero Member
  • *****
  • Posts: 850
    • View Profile
Re: operartion i/o with two sequential file
« Reply #1 on: June 01, 2023, 01:34:51 PM »
This should work, but i don't understand what the question is.
Btw, the last 'continue' is not needed.
Greetings from Groningen Netherlands <)))><.`.><(((>

monliv

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: operartion i/o with two sequential file
« Reply #2 on: June 01, 2023, 02:34:11 PM »
in my case it doesn't work,
what I find in tmp by reading of1
is a string that comes from if1,
maybe i need to close something...

Jean

  • Administrator
  • Hero Member
  • *****
  • Posts: 850
    • View Profile
Re: operartion i/o with two sequential file
« Reply #3 on: June 01, 2023, 03:17:24 PM »
Yes off course, i forgot that, you need lineread with an empty filename to close the file before you can use it again, it's in the help for lineread.
Alternatively you could use strlist, you can search in a strlist for something so you don't have to go through the whole file yourself.

Code: [Select]
while (TRUE = lineread(if1, tmp))               `read the 1 file
   {
   substr(tmp, 0, 60,name);           `I have the key to the file
   while (TRUE = lineread(of1, tmp))         `read the 2 file
        {
        substr(tmp, 0, 60,nameo);             `I'm going to check the second file if it's already there
        if (strcmp(name, nomeo) = 1) continue;`already present in the second file I do not add
        }
      linewrite(of1, name);                     ` write on 2 file I add   
      lineread("", tmp);                          lineread with an empty filename
      continue;
       }
Greetings from Groningen Netherlands <)))><.`.><(((>

Jean

  • Administrator
  • Hero Member
  • *****
  • Posts: 850
    • View Profile
Re: operartion i/o with two sequential file
« Reply #4 on: June 01, 2023, 03:41:33 PM »
This works:

Code: [Select]
char infile[256] = "d:\in\in.txt", outfile[256] = "d:\in\out.txt", tmp[256], name[61];
strlist(0, tmp, 0);                   ` create strlist
strlist(1, infile, 0);      ` load file into it
while (TRUE = lineread("d:\in\in1.txt", tmp))
  {
  substr(tmp, 0, 60, name);
  if (strlist(12, name, 0) < 0)
    linewrite(outfile, name);
  }
Greetings from Groningen Netherlands <)))><.`.><(((>

monliv

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: operartion i/o with two sequential file
« Reply #5 on: June 01, 2023, 04:34:29 PM »
Thanks Jean, I'd rather do it with two sequentials...
unfortunately when I start reading the second file, it always points to the first one.
Like it doesn't hear the command while (TRUE = linearread(of1, tmp)),
and continue reading the first file.
I tried closing the first file but nothing.
As if he didn't agree to read two cascading lines...
Anyway thanks for the advice... :'(

Jean

  • Administrator
  • Hero Member
  • *****
  • Posts: 850
    • View Profile
Re: operartion i/o with two sequential file
« Reply #6 on: June 01, 2023, 04:55:58 PM »
well, the strlist example works...

Also, when you post examples, please post working scripts so i can check them.
Greetings from Groningen Netherlands <)))><.`.><(((>

monliv

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: operartion i/o with two sequential file
« Reply #7 on: June 02, 2023, 09:33:08 AM »
ok Jean here an example. In the first file I have many Julius Caesars, in the second I would like to compact.
Using two sequential files do you think there is a solution?
Please rename livio.jpg livio.zip
Thanks

Jean

  • Administrator
  • Hero Member
  • *****
  • Posts: 850
    • View Profile
Re: operartion i/o with two sequential file
« Reply #8 on: June 02, 2023, 10:24:06 AM »
The forum won't let me open that, you could email it, but why don't you use the strlist? It's faster and it's less code.
Greetings from Groningen Netherlands <)))><.`.><(((>

Jean

  • Administrator
  • Hero Member
  • *****
  • Posts: 850
    • View Profile
Re: operartion i/o with two sequential file
« Reply #9 on: June 02, 2023, 11:34:49 AM »
I see, you are trying to use lineread on two separate files without closing one of them.
Greetings from Groningen Netherlands <)))><.`.><(((>

Jean

  • Administrator
  • Hero Member
  • *****
  • Posts: 850
    • View Profile
Re: operartion i/o with two sequential file
« Reply #10 on: June 02, 2023, 12:03:22 PM »
This does what you want.

Code: [Select]
char s[200],name[61],nameo[61],if1[256],of1[256],tmp[2000],tmpo[2000];
int i,larghezza,found;
window(screenwidth/3, screenheight*.75);
larghezza=screenheight*.75/9;`opt
strcpy(if1, "d:\in\in.txt");`input only
strcpy(of1, "d:\in\out.txt");`i/o
strlist(0, s, 0);
i=0;
while (TRUE = lineread(if1, tmpo))
      {
      substr(tmpo, 0, 60, nameo);
      if (strlist(12, nameo, 0) < 0)
        {
        strlist(3, nameo, 0);
        i += 1;
        }
       }
strcpy(s, "d:\in\out.txt");`i/o
strlist(8, s, 0);
strset(s, "Finished processing imported %3d", i);
say("",s);            `
@close;
run;
:close;
quit;
Greetings from Groningen Netherlands <)))><.`.><(((>

monliv

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: operartion i/o with two sequential file
« Reply #11 on: June 02, 2023, 12:14:02 PM »
works
the strlist function is very powerful, but I didn't know about it.
You are great!! good weekend ;D ;D ;D