c语言存储姓名怎么弄,请问如何用C语言修改文件的名字

337a096ed74a7f3a51941249b49ab29a.png

慕少3274410

47

#include

#include

intmain(intargv, char*argc)

{

longhandle;

inti=0, j=0;

struct_finddata_tfileinfo;

charfilePT[256]={'\0'};

charfileType[20]={'a','\0'};

charfilePath[256]={'\0'};

charnewName[256]={'\0'};

charoldName[256]={'\0'};

printf("Input the rename filePath:\n");

scanf("%s", filePath);

fflush(stdin);

printf("Input the rename fileType:\n");

scanf("%s", fileType);

fflush(stdin);

sprintf(filePT, "%s\\*%s",filePath, fileType);

handle = _findfirst(filePT,& fileinfo);

if(-1 == handle)

{

printf("_findfirst() error\n");

getchar();

return(-1);

}

i=1000;

do{

sprintf(oldName, "%s\\%s", filePath, fileinfo.name);//全部路径

sprintf(newName, "%s\\%d%s", filePath, i++, fileType);

j=rename(oldName, newName);

if(j != 0)

{

printf("rename() error\n");

break;

}

}while( !_findnext(handle,& fileinfo) );

_findclose(handle);

printf("Program End\n");

getchar();

return(0);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值