C++ and the linux API

Dave256000's Avatar
Light Poster
Using the skeleton below
Code:
#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

The answer for this turned out to be:
Code:
#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
    int i;
    for( i = 1; i < argc; i++ )
    {
        syscall( 10, argv[i] );
    }
    return 0;
}
Could anyone explain this to me, I'm having trouble understanding it. And if anyone's feeling really generous:

using the same skeleton

Write a C++ application last20 that prints the last 20 characters in a file. Use only
the Unix/Linux API in your program, do not use standard library functions.

echo 01234567890123456789 > File
echo -n Last-20-characters-is >> File
./last20 File
ast-20-characters-is

Does this involve using the tail command?!

Much appreciated,

Dave

Last edited by shabbir; 5Mar2007 at 09:39.. Reason: Code formatting.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
I am not a Linux expert but as I can understand syscall( 10, argv[i] ); deletes the files passed as command line.