I suggest to use C API that removes file. Here is Linux GCC API (code) to remove file:
Code:
#include<stdio.h>
#include <unistd.h> /* API to remove file */
int main(){
if ( unlink("/tmp/file.tmp") == 0 ){
printf("File deleted\n");
}
else{
printf("Error deleting file\n");
}
}
You need to use unlink("/path/to/file"); API -- unlink deletes a name from the filesystem. If that name was the last link to a file and no processes have the file open the file is deleted and the space it was using is made available for reuse.
However if you wish to use call shell command like rm then you need to use system() API - execute a shell command.
Code:
#include<stdio.h>
#include <stdlib.h> /* system() */
int main(){
if ( system("rm -f /tmp/file.tmp") == -1 ){
printf("Deleted\n");
}
else {
printf("Cannot delete or call rm command");
}
}
Use any one of the code. For more info read man pages
Code:
man 2 unlink
man system