C 中的 rename() 函數
rename() 函數定義在<stdio.h>
頭文件。
原型:
int rename(const char* old-filename, const char* new-filename);
參數: const char* old-filename, const char* new-filename
返回類型: int
函數的使用:
當我們處理文件時,有時我們需要重命名一些文件。在文件處理中,我們使用 rename() 函數來重命名文件。函數 rename() 的原型是int rename(const char* old-filename, const char* new-filename);
這裏,old-filename
是必須使用新名稱重命名的文件的先前名稱new-filename
.如果文件成功重命名,則返回零,如果發生錯誤,則返回非零。
C 中的 rename() 示例
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE* f;
//Check the existence of that file
if ((f = fopen("includehelp.txt", "r")) == NULL) {
printf("File does not exist...\n");
}
else {
printf("File is exist.\n");
}
fclose(f);
//Rename the file
if (rename("includehelp.txt", "new_includehelp.txt"))
printf("Rename error.....\n");
else
printf("File is renamed\n");
if ((f = fopen("includehelp.txt", "r")) == NULL) {
printf("File does not exist...\n");
}
else {
printf("File is exist.\n");
}
fclose(f);
if ((f = fopen("new_includehelp.txt", "r")) == NULL) {
printf("File does not exist...\n");
}
else {
printf("File is exist.\n");
}
fclose(f);
return 0;
}
輸出


相關用法
- C語言 remove()用法及代碼示例
- C語言 rewind()用法及代碼示例
- C語言 fread()用法及代碼示例
- C語言 feof()用法及代碼示例
- C語言 imagesize()用法及代碼示例
- C語言 getarcoords()用法及代碼示例
- C語言 strcspn()用法及代碼示例
- C語言 setlinestyle()用法及代碼示例
- C語言 showbits()用法及代碼示例
- C語言 sprintf()用法及代碼示例
- C語言 outtextxy()用法及代碼示例
- C語言 isgraph()用法及代碼示例
- C語言 grapherrormsg()用法及代碼示例
- C語言 moveto()用法及代碼示例
- C語言 putchar()用法及代碼示例
- C語言 tmpnam()用法及代碼示例
- C語言 putpixel()用法及代碼示例
- C語言 fillellipse()用法及代碼示例
- C語言 outtext()用法及代碼示例
- C語言 atan2()用法及代碼示例
注:本文由純淨天空篩選整理自Souvik Saha大神的英文原創作品 rename() function in C language with Example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。