Valhalla Legends Forums Archive | C/C++ Programming | Re: Simple Program

AuthorMessageTime
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 Offspring131313@yahoo.com

I have C++ 6.0 and the compiler, I just don't remember how to write the code anymore.
September 29, 2005, 12:46 AM
Kp
This is off-the-cuff, so no warranties.  That said:

[code]#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);
  }
}[/code]

It should be pretty obvious how it works.  Tweak it a bit for your offsets and you're good to go.
September 29, 2005, 1:14 AM
Myndfyr
<3 Kp.  :)
October 3, 2005, 6:05 PM
Mangix
[quote]C++ 6.0 and the compiler
[/quote]*Microsoft Visual C++ 6.0
C++ isnt a program or compiler
October 5, 2005, 11:14 PM
Yoni
Kp:

You get a gold star.
October 8, 2005, 12:47 AM

Search