C 報錯 [Error] lvalue required as left operand of assignment

/*  test.c  */

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main ()
{
        char *src = "hello,My girlfriend";
        int len = strlen(src);
        char *dest = (char *)malloc(len);
        char *d = dest;
        char *s = src[len];

        while(len--!=0) //應將 = 改爲 :==
        {
                d++=s--;
        }
        printf("%s",dest);
        return 0;
}

[Error] lvalue required as left operand of assignment

原因:

計算值爲== !=

變量爲=

 賦值語句的左邊應該是變量,不能是表達式。而實際上,這裏是一個比較表達式,所以要把賦值號(=)改用關係運算符(==)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章