const也不能保证

来源:互联网 发布:macbook办公软件下载 编辑:程序博客网 时间:2024/04/30 01:44

代码:

#include <stdio.h>

#include <string.h>


void test(const char *paszStr)
{
        char *pSearch =  (char *)strrchr(paszStr, '/');
        if(NULL != pSearch)  
        {
                *pSearch = '\0';
        }
        return;
}


int main()
{
        char sz[] ="my/test/file/touch" ;


        printf("old: %s\n", sz);
        test(sz);
        printf("new: %s\n", sz);


        return 0;

}


执行结果:

old: my/test/file/touch
new: my/test/file