-->
Showing posts with label program to understand rename() function. Show all posts
Showing posts with label program to understand rename() function. Show all posts

program to understand rename() function

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

int main()
{
  char first_name[40],second_name[40];

  printf("enter file name with extension .txt\n");
  gets(first_name);
  printf("enter name to be changed\n");
  gets(second_name);
    rename("first_name","second_name");
    printf("the entered file renamed 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 rename() function
#include <stdio.h>
#include<conio.h>
int main()
{
  char first_name[40],second_name[50];
  printf("enter file name with extension .txt\n");
  gets(first_name);
    printf("enter name to be changed\n");
    gets(second_name);
    rename("first_name","second_name");
    printf("the entered file renamed successfully");
    getch();
    return 0;
}
*/

-------------------------------------
same program, we can use for turboc++ as well