C examples for stdio.h:rename
function
<cstdio> <stdio.h>
Rename a file
int rename ( const char * oldname, const char * newname );
Parameter | Description |
---|---|
oldname | an existing file to be renamed. |
newname | new name for the file. |
On success, a zero value is returned.
On failure, a nonzero value is returned.
#include <stdio.h> int main ()//w ww. ja v a 2s.c o m { int result; char oldname[] ="main.cpp"; char newname[] ="newname.txt"; result= rename( oldname , newname ); if ( result == 0 ) puts ( "File successfully renamed" ); else perror( "Error renaming file" ); return 0; }