rename - C stdio.h

C examples for stdio.h:rename

Type

function

From


<cstdio>
<stdio.h>

Description

Rename a file

Prototype

int rename ( const char * oldname, const char * newname );

Parameters

ParameterDescription
oldname an existing file to be renamed.
newname new name for the file.

Return value

On success, a zero value is returned.

On failure, a nonzero value is returned.

Demo Code


#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;
}

Related Tutorials