Skip to content

Instantly share code, notes, and snippets.

@mohamad-wael
Created May 7, 2021 20:51
Show Gist options
  • Save mohamad-wael/f351fb422b664b4d6a5ea4d931573488 to your computer and use it in GitHub Desktop.
Save mohamad-wael/f351fb422b664b4d6a5ea4d931573488 to your computer and use it in GitHub Desktop.
How to remove files , using the stdio header in C .
#include <stdio.h>
#include <stdlib.h>
/* Program to remove files .
It can also remove empty directories
under linux , but directories
cannot be removed under windows .*/
int
main (int argc , char * argv [ ] ){
char * fileToDelete , * progName;
progName = argv [0 ];
if (argc != 2 ){
fprintf (stderr , "Usage: %s filename\n" , progName );
exit (EXIT_FAILURE ); }
fileToDelete = argv [1 ];
if (remove (fileToDelete ) == 0 )
printf("The file %s , has been deleted .\n" , fileToDelete );
else
perror(fileToDelete );}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment