C Programming
Computer Programming

C file handling program to rename a file using the system() function specifying the "ren" command



Write C file handling program to rename a file using the system() function specifying the "ren" command

\* C file handling program to rename a file using the system() function specifying the "ren" command *\

# include < stdio.h >
# include < stdlib.h >
int   main( )
{

char oldName[20] ;
char newName[20] ;
char cmd[64] ;
int ret = 0 ;
printf("\n Enter old filename: ") ;
scanf("%s", oldName ) ;
printf(" Enter new filename: ") ;
scanf("%s", newName ) ;
sprintf(cmd, "ren %s %s", oldName, newName ) ;
ret = system(cmd) ;
if (ret == 0)
      printf(" File renamed successfully !\n") ;
else
      printf(" Unable to rename file !\n") ;
return 0;

}

Output of Program :

Output of C file handling program to rename a file using the system() function specifying the ren command