c语言 函数的参数传递示例
C语言中的rename()函数 (rename() function in C)
The rename() function is defined in the <stdio.h> header file.
在<stdio.h>头文件中定义了rename()函数 。
Prototype:
原型:
int rename(const char* old-filename, const char* new-filename);
Parameters: const char* old-filename, const char* new-filename
参数: const char *旧文件名,const char *新文件名
Return type: int
返回类型: int
Use of function:
使用功能:
When we are dealing with files then sometimes we need to rename some files. In file handling, we use rename() function to rename the files. The prototype of the function rename() is int rename(const char* old-filename, const char* new-filename);
当我们处理文件时,有时我们需要重命名一些文件。 在文件处理中,我们使用rename()函数来重命名文件。 函数rename()的原型是int named(const char * old-filename,const char * new-filename);
Here, old-filename is the previous name of the file which has to renamed with the new name as new-filename. It returns zero if the file is successfully renamed and non-zero if an error has occurred.
在这里, old-filename是文件的先前名称,必须使用新名称将其重命名为new-filename 。 如果文件已成功重命名,则返回零;如果发生错误,则返回非零。
C中的named()示例 (rename() example in C)
#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;
}
Output
输出量
![rename() example in C language](https://i-blog.csdnimg.cn/blog_migrate/a519e37a3181aa839ad1865527180d30.png)
![rename() example in C language](https://i-blog.csdnimg.cn/blog_migrate/916ac59b9ed4a89926b2a3c118420962.png)
翻译自: https://www.includehelp.com/c-programs/rename-function-in-c-language-with-example.aspx
c语言 函数的参数传递示例