C - Incompatible types when assigning to type 'char[LENGTH]' from type 'char *' -
this question has answer here:
i want assign struct value (that can max 50 characters) standard input getting error:
incompatible types when assigning type 'char[50]' type 'char *'
#include <stdio.h> #include <stdlib.h> #define max_len 50 struct msgbuf { char mtext[max_len]; }; int main (int argc, char *argv) { struct msgbuf m; char in[max_len]; scanf ("%s", in); m.mtext = in; }
arrays have no copy assignment operator. have copy arrays element element. can use standard function strcpy declared in header <string.h> copy strings. example
#include <string.h> //... strcpy( m.mtext, in );
Comments
Post a Comment