C++ dilemma

Discussion in 'C++' started by Dave256000, Feb 28, 2007.

  1. Dave256000

    Dave256000 New Member

    Joined:
    Feb 28, 2007
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    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 not sure what the answer
    is. Someone please help?!
     
  2. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    Show a couple of your ages worth of tries.
     
  3. Dave256000

    Dave256000 New Member

    Joined:
    Feb 28, 2007
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    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?
     
  4. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    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.
     
  5. Dave256000

    Dave256000 New Member

    Joined:
    Feb 28, 2007
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  6. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    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.
     
  7. Dave256000

    Dave256000 New Member

    Joined:
    Feb 28, 2007
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    sounds like 'one' needs to see a quack. I figured it out, by the way
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice