-->
Showing posts with label Program to understand remove() function.. Show all posts
Showing posts with label Program to understand remove() function.. Show all posts

Program to understand remove() function.

using codeblocks
--------------------------------------------------------------------------------------------
//understanding remove() function
#include <stdio.h>
#include<conio.h>

int main()
{
  char file_name[40];
  FILE *k;
  printf("enter file name with extension .txt\n");
  gets(file_name);

k=fopen("file_name","w");
if(k==NULL)
{
    printf("sorry,  not found\n ");
}
else
{
    remove("file_name");
    printf("the entered file removed successfully");
}
    getch();
    return 0;
}

//note: We do not need to open file here. We can do without opening too(from line 19).
/*i.e
//understanding remove() function
#include <stdio.h>
#include<conio.h>

int main()
{
  char file_name[40];
  printf("enter file name with extension .txt\n");
  gets(file_name);

    remove("file_name");
    printf("the entered file removed successfully");

    getch();
    return 0;
}
*/