C Programming
Computer Programming

C file handling program to delete a specified file using the system() function by passing the "rm" command



Write C file handling program to delete a specified file using the system() function by passing the "rm" command

\* C file handling program to delete a specified file using the system() function by passing the "rm" command *\

# include < stdio.h >
# include < stdlib.h >
int   main( )
{

char filename[15] ;
char cmd[32] = { 0 } ;
int ret = 0 ;
printf("\n Enter the filename to be deleted : " ) ;
scanf("%s", filename) ;
sprintf(cmd, "rm %s", filename) ;
ret = system(cmd) ;
if (ret == 0)
      printf(" File deleted successfully\n") ;
else
      printf(" Unable to delete file %s\n", filename ) ;

return 0 ;

}

Output of Program :

Output of C file handling program to delete a specified file using the system() function by passing the rm command