Thread: Writing a Unix Search Program, some questions

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    21

    Writing a Unix Search Program, some questions

    Hey, for my Systems Programming course this semester, our prof has given us an assignment to create a Unix search program in C. Essentially, you give it a file name, go through each file, compare against it and return a true or false result. It also needs to search subdirectories.

    However, naturally, we don't have anything in our text covering this...yay. So, what code would I use to a) cycle through a list of files and b) compare a string against a file name. Obviously, not asking you to write my program for me, I just need to know what to use in these instances. If you've got any resources for writing Unix programs in C, as well, please link them, as that's what the course is on.

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I have posted code that is unix compatible that does this in the past. If it still exists, feel free to just copy mine (and learn nothing). If the threads were old enough to be purged, just show us where you are thus far and we can baby step you through it.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    There's even a tree walker in the FAQ....

    But if you want to try yourself without peeking at the answer, look up these functions in the manual pages
    - opendir
    - readdir
    - closedir
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    477
    Write a function that lists all files in a dir - that's easy. When one of the files listed is a directory, append it to the current working directory and pass that path to the function that lists files in a dir. You might want to consider some kind of a multi-threading mechanism to speed it up, or fork(I've never used fork, not a big linux programmer, but I imagine it could be used to accomplish the task - If I'm wrong, be kind as to correct me).
    "What's up, Doc?"
    "'Up' is a relative concept. It has no intrinsic value."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Writing a program to make a calendar
    By Northstar in forum C Programming
    Replies: 17
    Last Post: 11-07-2007, 11:34 AM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  3. writing a grep program
    By cnovice in forum C Programming
    Replies: 8
    Last Post: 11-22-2005, 08:05 AM
  4. writing a program called tail like the one in unix
    By fanaonc in forum C Programming
    Replies: 2
    Last Post: 11-04-2001, 02:20 AM
  5. Remotely accessing an NT PC from a Unix C++ program
    By bhorrobi in forum C++ Programming
    Replies: 0
    Last Post: 10-01-2001, 09:42 AM