C++ dilemma
Using the skeleton below
#include <unistd.h> // read/write #include <sys/file.h> // open/close values #include <string.h> // strlen int main( int argc, char *argv[], char *env[] ) { // C++ or C code } Write a C++ application myrm that removes (deletes) files passed as command line argument. Use only the Unix/Linux API in your program, do not use standard library functions. echo > File1 ./myrm File1 I've been trying for aages and any help or advice would be greatly appreciated. Dave |
|
Quote:
|
The clue that you need is in the skeleton code that you posted. You are obviously required to use functions that are in (and are only in) the #includes. Look at these files, see what is available and use those that help you answer the problem.
|
still no joy
Thankyou for your replies, but don't forget somewhere in there I have to write an application myrm that deletes the given file. So that already gives away that I have to use the rm command.
I just can't get my head around how I fit that into the skeleton provided. Can I pass files to the rm command as a parameter? and if so, why is the skeleton structured like that? Also, how do I call an application like that from that c++ skeleton? Someone, throw me a bone here! Dave |
Quote:
Here's another: http://www.die.net/doc/linux/man/man2/unlink.2.html Quote:
|
Quote:
BlueSloth |
still stuck
ok,
so say I write an application that uses the unlink() command. how would i pass a parameter (i.e. file) to that for example if /.myrm file1 removes file1. whats inside myrm that's passing the parameter to the unlink() command? As you can tell, I'm completely new to this and appreciate the help. |
If you are completely new to 'c' I recommend getting yourself a book about it. I have one and it helps me when I get confused about the syntax. Also, you learn stuff in the 'correct' order.
This page has some interesting tutorials for both 'c' and 'c++' http://www.cprogramming.com/tutorial.html File I/O is described here: http://www.cprogramming.com/tutorial/lesson10.html |
Quote:
|
Quote:
A good first test program for you to make would be to work out how to make a program called "test1", which, when invoked like this: Code:
./test1 argument1 second_argument 3rd-arg Code:
argument 1 is: argument1
|
All times are GMT -5. The time now is 02:14 PM. |