//* Rename a file *

#ifdef _MSC_VER // for MS Visual Studio compilers - to allow "classic" insecure printf and scanf #define _CRT_SECURE_NO_WARNINGS #endif #include <stdio.h> int main() { char inName[80]; char outName[80]; int status; // prompting user for filenames printf("Rename: "); scanf(" %79[^\n]s\n", inName); printf("to: "); scanf(" %79[^\n]s\n", outName); status = rename(inName, outName); if ( status==0 ) { printf("File %s is now renamed to %s.\n", inName, outName); } else /* status==-1 */ { printf("Renaming %s to %s failed.\n", inName, outName); // will fail on inName not existing, or outName exisiting // not too mention insufficient access privileges } return(0); }