Q:

C program to delete a file

0

C program to delete a file

 

C program to delete a file whose name (with extension) a user will input. The file must be present in the directory in which the executable of this program is present. Macro "remove" is used to delete the file. If there is an error in deleting the file, then it will be displayed by perror function.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <stdio.h>
int main()
{
  int status;
  char file_name[25];

  printf("Enter name of a file you wish to delete\n");
  gets(file_name);

  status = remove(file_name);

  if (status == 0)
    printf("%s file deleted successfully.\n", file_name);
  else
  {
    printf("Unable to delete the file\n");
    perror("Following error occurred");
  }

  return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now