c 字符串拼接更加方便
时间:2010-11-02 来源:teiller2008
int main(void)
{
char fullpath [100] = "/home/dimgtui"; //记录路径名
printf("fullpath:%s\n",fullpath);
char * ptr;//记录fullpath的最后位置,用于拼接
ptr = fullpath + strlen(fullpath);
*ptr ++ = '/';
*ptr = 0;
char * filename = "filename1";
strcpy(ptr,filename);
printf("fullpath:%s\n",fullpath);
//恢复之前的fullpath
ptr[-1] = 0;
printf("fullpath:%s\n",fullpath);
exit(0);
}
/*output
fullpath :"/home/dimgtui"
fullpath :"/home/dimgtui/filename1"
fullpath :"/home/dimgtui"
*/
相关阅读 更多 +