//* Delete a file or a directory, one, two, three, gone *

#ifdef _MSC_VER // for MS Visual Studio compilers - to allow "classic" insecure printf and scanf #define _CRT_SECURE_NO_WARNINGS #endif #include <stdio.h> int main() { char fileName[80]; int status; printf("Delete the file: "); scanf(" %79[^\n]s\n", fileName); status = remove(fileName); // Note: unlink(.) does the same thing but it is Unix specific if ( status==0 ) { printf("%s is now gone!\n", fileName); } else { FILE *test = fopen(fileName, "r"); if (test!=0) { fclose(test); printf("%s cannot be deletedQ\n", fileName); } else /* test==-1 */ { printf("Does %s even exist?\n", fileName); } } return(0); }