“assignment discards 'const' qualifier” error on non-const pointer

后端 未结 3 1311
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-19 01:47

In the following function:

char *mystrtok(const char *input, const char *delim,char *rest) {
    int i;
    for (i = 0; input[i] != *delim && input[i         


        
3条回答
  •  迷失自我
    2021-01-19 02:17

    you could also cast your 'input' variable with a (char*) type which would resolve the warning. just be careful using explicit casts like this so as not to modify constants themselves.

    rest = (char*)input + i + 2;
    

提交回复
热议问题