assignment makes integer from pointer without a cast

后端 未结 2 890
南方客
南方客 2021-01-29 08:34

In the below code am getting an error while am assigning len1 to array a The error is

assignment makes integer from pointer without a         


        
2条回答
  •  北恋
    北恋 (楼主)
    2021-01-29 09:07

    What are the types of the (sub-)expressions in your statement?

    a[4] = len1;
    

    len1 is an array of 50 chars (type char[50]) but in the expression above it decays to a pointer to its first element. That's a value of type char*.
    a[4] is an object of type char.

    You cannot assign a char* to an object of type char!

    I think maybe you wanted

    /* BEWARE BUFFER OVERFLOWS */
    strcpy(a+4, len1); /* a+4 is of type `char*`, len1 decays to `char*` */
    

提交回复
热议问题