Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   C++ dilemma (http://www.go4expert.com/forums/cpp-dilemma-t3201/)

Dave256000 28Feb2007 23:02

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

echo > File1
./myrm File1

I've been trying for aages and not sure what the answer
is. Someone please help?!

DaWei 1Mar2007 16:14

Re: C++ dilemma
Show a couple of your ages worth of tries.

Dave256000 2Mar2007 13:18

Re: C++ dilemma
I have this:

$ echo > File1
$ echo > File2

$ ls
File1 File2 myrm.c

$ gcc -g -Wall -W -pedantic -o myrm myrm.c

myrm.c:1:21: warning: C++ style comments are not allowed in ISO C90
myrm.c:1:21: warning: (this will be reported only once per input file)
myrm.c:4: warning: unused parameter ‘env’

$ ./myrm File1
$ ls
File2 myrm myrm.c

$ echo > File1
$ ./myrm File1 File2
$ ls
myrm myrm.c

but i'm still none the wiser how I would fit that into C++ skeleton?

DaWei 2Mar2007 14:32

Re: C++ dilemma
Quite frankly, this looks like the quite common case of some jerk not paying attention in class, expecting that he or she can get their work done, well and for free, on some forum. Review your materials regarding how to get an argument from the command line (hint: argc/argv), and how to remove or delete a file with the functions available in the Unix/Linux API. You may get some newb showoff who will write this for you, thus generating another person we have to watch out for when we're hiring. You won't get it from me.

Dave256000 2Mar2007 16:14

Re: C++ dilemma
Jerk? Not paying attention in class? You don't know me mate, I got an A for Java and I've just been introduced to C++ and linux. Thought maybe I could get some hints and tips and I've been given them. I've gone through the linux and C++. I'm aware that I need to use the unlink() function, I'll figure it out.
I would retort with an insult but you're not worth it - whatever you're hiring I'm not applying for

DaWei 2Mar2007 19:01

Re: C++ dilemma
That's certainly your prerogative. You will find that people operate on the premise that if it looks like a duck, walks like a duck, and quacks, then it's a duck. It's entirely possible that a mistake was made. One could have encountered a chicken that is a master of disguise and impersonation. One doesn't have the time to investigate all fowl to see if they are a chicken in duck's clothing; one falls back on much experience.

Dave256000 4Mar2007 15:38

Re: C++ dilemma
sounds like 'one' needs to see a quack. I figured it out, by the way

All times are GMT +5.5. The time now is 21:00.