void deal_path(char* path,unsigned long size)
{
//path为传入的路径
char tmp[1024];
int len = strlen(path);
int last_index = 0;
printf("len is %d\n",len);
for(int i = 0; i < len; i++)
{
if('\\' == path[i]
{
last_index = i;//这里last_index会记住最后一个反斜杠的index
}
}
printf("1---last_index is %d\n",last_index);
printf("2---path is %s\n",path);
printf("3---path[last_index] is %c\n",path[last_index];
strcpy(tmp, path, last_index + 1);
tmp[last_index + 1] = '\0';
strncpy(&tmp[last_index + 1], "aaa.bin", 8);//此处不可以用strcat,考虑一下为什么
printf("4---tmp is %s\n", tmp);
return;
}
打印结果如下,将文件名改成aaa.bin