Error C2106 Struct
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings left operand must be l-value in c and policies of this site About Us Learn more about Stack Overflow must be lvalue javascript the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation error c2106 '=' left operand must be l-value Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up left operand must be l-value , C programing up vote 1 down vote favorite am trying to understand how link lists work ; and on changing example code from tutor I get the 'left operand must be l-value' error ...here is my code. Any help appreciated :) struct node { char name[20]; struct node *next; }; /*Function to allocate memory and initialize node - returns pointer to node*/ struct node*mknode(char *str) { struct node *np; np = (struct node*)malloc(sizeof(struct node)); if(np) { np->name = *str; np->next = NULL; /*sets the 'next' pointer to last list item to NULL*/ } return np; } int main(void) { int i,menu,k=1,number; char name[20]; char *str = name; struct node* n; struct node *head=NULL; printf("Link Lists\n 1-Enter Data into lists\n 2-Display All List Items\n 3-Quit Program :(\n"); do { printf("\nPlease choose an option: "); scanf("%d",&menu); switch (menu) { case 1: printf("\nPlease Enter A Number:"); scanf("%d",&name); n=mknode(str); /*create new node with i as data*/ append_node(&head,n); /*add new node to end of list*/ break; this is where i get the error np->name = *str; after changing the structures data type from integer to char thanks c share|improve this question asked Mar 7 '13 at 21:22 Dex Dave 651211 You're treating np->name as a pointer, when it's an array. You can't assign something to an array. –teppic Mar 7 '13 at 21:25 You can't ass
Search Username Password Remember Me? Register Lost Password? facebook google twitter rss Free Web Developer Tools Advanced Search Forum Programming Languages C Programming Trouble initializing array of structs, error C2106: '=' : left operand must be l-valu Thread: Trouble initializing array of structs, error C2106: '=' : left operand must be l-valu Share This Thread Tweet This + 1 this Post To Linkedin Subscribe to this Thread Subscribe to This Thread November 19th, 2003,07:43 PM #1 No Profile Picture Scoobiez View Profile View Forum Posts Junior Member Devshed Newbie (0 - 499 posts) Join Date Nov 2003 Location http://stackoverflow.com/questions/15282003/left-operand-must-be-l-value-c-programing FL Posts 6 Rep Power 0 Trouble initializing array of structs, error C2106: '=' : left operand must be l-valu [FONT=courier new] I am trying to initialize and array of structs....struct is called pb_entry and the array is phone_book. When I follow "correct"syntax I get the following error: error C2106: '=' : left operand must be l-value Here is the segment of my code that applys(I assure that the http://forums.devshed.com/programming-42/trouble-initializing-array-structs-error-c2106-left-operand-valu-99683.html rest of the code is correct since it is quite simple): typedef struct { char last_name[15]; char first_name[15]; char mid_init[3]; char address[50]; char phone_num[15]; }pb_entry; int j = 0; pb_entry phone_book[SIZE]; for(j=0; j<=SIZE; j++) { phone_book[j].last_name = " "; phone_book[j].first_name = " "; phone_book[j].mid_init = " "; phone_book[j].address = " "; phone_book[j].phone_num = " "; } Basic jist of the code it to construct a phone book. This segment(and again, I've only posted relevant code) initializes the array of structs to be "blank". However when I compile I get the error noted above. SIZE is declared to be 100 Any insight on what it means? What is l-value? Sorry newbie here. Thanks for any input! Regards Faq Reply With Quote November 19th, 2003,08:56 PM #2 dwise1_aol View Profile View Forum Posts Contributing User Devshed Supreme Being (6500+ posts) Join Date Jan 2003 Location USA Posts 7,323 Rep Power 2225 Basic computer science theory applicable to almost all programming languages (statement qualified since I'm sure somebody out there was perverse enough to create a language to which this does not apply): In an assignment statement, you have two
Support Support Newsreader MathWorks Search MathWorks.com MathWorks Newsreader Support MATLAB Newsgroup MATLAB Central Community Home MATLAB Answers File Exchange Cody Blogs Newsreader Link Exchange ThingSpeak Anniversary Home Post A New Message Advanced Search Help MATLAB Central Community Home MATLAB Answers File Exchange Cody Blogs Newsreader https://www.mathworks.com/matlabcentral/newsreader/view_thread/243202 Link Exchange ThingSpeak Anniversary Home Post A New Message Advanced Search Help Trial software mxCreateStructMatrix problem Subject: mxCreateStructMatrix problem From: Sebastien Paris Sebastien PARIS (view profile) (Sebastien Paris) 26 posts Date: 27 Jan, 2009 12:28:02 Message: 1 of 7 Reply to this message Add author to My Watch List View original format Flag as spam Hello, I got some problem when using mxCreateStructMatrix in a mexfile, and I don't know to proceed. I got the following structure : struct must be mystruct { double *a; double *b; double *c; double *d; }; a function : void myfunc(double *, double *, double *, double *); The mex gateaway creating a structure with 4 fields is : void mexFunction( int nlhs, mxArray *plhs[] , int nrhs, const mxArray *prhs[] ) { const char *fieldnames[] = {"a", "b" , "c" , "d"}; int T =100; struct mystruct *X; plhs[0] = mxCreateStructMatrix(1 , 1 , 4 , fieldnames); for(i = 0 ; i < left operand must 4 ; i++){ mxSetFieldByNumber(plhs[0] ,0 , i , mxCreateNumericMatrix(T, 1 , mxDOUBLE_CLASS, mxREAL)); } X = plhs[0]; myfunc(X->a, X->b,X->c,X->d); } If I debug, X->a is not memory allowed (neither X->b, X->c, X->d), for example I can't read/write in X.a[0] for example. I probably miss something, anyone can help me ? Subject: mxCreateStructMatrix problem From: Steven Lord Steven Lord (view profile) 10595 posts Date: 27 Jan, 2009 14:38:42 Message: 2 of 7 Reply to this message Add author to My Watch List View original format Flag as spam "Sebastien Paris"