string literal in c

前端 未结 6 984
刺人心
刺人心 2021-01-05 09:12

Why is the following code illegal?

typedef struct{
   char a[6];
} point;

int main()
{
   point p;
   p.a = \"onetwo\";
}

Does it have any

6条回答
  •  借酒劲吻你
    2021-01-05 10:14

    No strcpy or C99 compund literal is needed. The example in pure ANSI C:

    typedef struct{
       char a[6];
    } point;
    
    int main()
    {
       point p;
       *(point*)p.a = *(point*)"onetwo";
       fwrite(p.a,6,1,stdout);fflush(stdout);
       return 0;
    }
    

提交回复
热议问题