Created
May 7, 2021 20:51
-
-
Save mohamad-wael/f351fb422b664b4d6a5ea4d931573488 to your computer and use it in GitHub Desktop.
How to remove files , using the stdio header in C .
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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