User Tools

Site Tools


c:stdio.h:rename

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

c:stdio.h:rename [2024/02/16 01:05] (current)
Line 1: Line 1:
 +{{keywords>wiki library source code example reference}}
 +
 +====== rename ======
 +
 +<code c>
 +
 +int rename(const char *old_filename, const char *new_filename);
 +
 +</code>
 +
 +Changes name of file oldname to newname. Returns non-zero on failure.
 +
 +===== Example Source =====
 +<code c>
 +/* 
 + * rename example code
 + * http://code-reference.com/c/stdio.h/rename 
 + */
 +
 +#include <stdio.h> /* including standard library */
 +//#include <windows.h> /* uncomment this for Windows */
 +
 +#define FILENAME "test_tmp.txt"
 +
 +int main ( void )
 +{
 +FILE *tmpfile;
 +char string[20];
 +tmpfile = fopen(FILENAME, "w");
 +
 +if (tmpfile == 0 ) {
 +perror("cannot open file");
 +}
 +
 + fprintf (tmpfile, "temporary file for c remove example\n");
 + fclose(tmpfile);
 +
 + rename (FILENAME,"test_new.txt");
 + 
 + return 0; 
 +}
 +</code>
 +
 +==== output ====
 +    ./rename
 +    
 +    file will be created
 +    write text into file "temporary file for c rename example"
 +
 +    file will be renamed into test_new.txt
  

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
c/stdio.h/rename.txt · Last modified: 2024/02/16 01:05 (external edit)

Impressum Datenschutz