• Welcome to Valhalla Legends Archive.
 

Simple Program

Started by Meta-Ridley, September 28, 2005, 07:46 PM

Previous topic - Next topic

Meta-Ridley

It's been quite a loooong time since i've touched C++, years in fact.  And after these many years, I've found a very simple but effective use for it where I work.  However, because it's been so long since I've used C++, I dont remember a thing.  If someone could help build this program, I would be infinately grateful.  The thing the program needs to do:
1. Take .txt files from a floppy
2. Take certain specified characters from the .txt file from which the location on the txt file should never change, and print these characters in another seperate .txt file.
3. Cycle through all .txt files on the floppy

Like I said, simple program.  If someone could help me out with this, I would be very appreciative.

EDIT:  One thing I forgot to mention, if someone would like to help me out, please E-Mail me at [email protected]

I have C++ 6.0 and the compiler, I just don't remember how to write the code anymore.

Kp

This is off-the-cuff, so no warranties.  That said:

#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <dirent.h>

static void handle_txt(const char *name) {
  char buf[32];
  int fd = open(name, O_RDONLY), fd2;
  if (fd < 0)
    return;
  fd2 = open("/tmp/other_text_file.txt", O_WRONLY | O_CREAT | O_APPEND, 0666);
  if (fd2 < 0) {
    close(fd);
    return;
  }
  lseek(fd, OFFSET1, SEEK_SET);
  read(fd, buf, LENGTH1);
  write(fd2, buf, LENGTH1);
  close(fd);
  close(fd2);
}

int main(int argc, char **argv) {
  DIR *dir = opendir("/mount/floppy");
  struct dirent *de;
  if (!dir)
      return 1;
  chdir("/mount/floppy");
  while ((de = readdir(dir)) != NULL) {
    int l = strlen(de->d_name);
    if (l < 4 || strcmp(de->d_name + l - 4, ".txt"))
      continue;
    handle_txt(de->d_name);
  }
}


It should be pretty obvious how it works.  Tweak it a bit for your offsets and you're good to go.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

MyndFyre

QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Mangix

QuoteC++ 6.0 and the compiler
*Microsoft Visual C++ 6.0
C++ isnt a program or compiler

Yoni

Kp:

You get a gold star.