left operand must be l-value

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Sep 2007
Posts: 271
Reputation: fatihpiristine has a little shameless behaviour in the past 
Solved Threads: 16
fatihpiristine's Avatar
fatihpiristine fatihpiristine is offline Offline
Posting Whiz in Training

left operand must be l-value

 
0
  #1
Nov 4th, 2009
what's wrong here?

  1. typedef struct person
  2. {
  3. int age;
  4. char name[50];
  5. };
  6.  
  7. int main()
  8. {
  9. struct person test;
  10.  
  11. test.age = 20;
  12. test.name = "Test";
  13.  
  14. return 0;
  15. }
Do a favour, leave me alone
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 271
Reputation: fatihpiristine has a little shameless behaviour in the past 
Solved Threads: 16
fatihpiristine's Avatar
fatihpiristine fatihpiristine is offline Offline
Posting Whiz in Training
 
0
  #2
Nov 4th, 2009
anyways i fixed it myself here is the solution

  1.  
  2. typedef struct
  3. {
  4. int age;
  5. char *name[50];
  6. } Person;
  7.  
  8. Person newperson(char *name, int age)
  9. {
  10. Person temp;
  11. *temp.name = name;
  12. temp.age = age;
  13. return temp;
  14. }
  15.  
  16. int main()
  17. {
  18. Person list[50], ttt;
  19.  
  20. list[0] = newperson("Test", 20);
  21.  
  22.  
  23.  
  24. *ttt.name = "ASDF";
  25.  
  26.  
  27.  
  28. return 0;
  29. }
Do a favour, leave me alone
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,433
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 249
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c
 
0
  #3
Nov 4th, 2009
Use strcpy to copy a string. You've got more going wrong in that code, though. I think you're after something that might look a bit like this:
  1. #include <string.h>
  2.  
  3. typedef struct
  4. {
  5. int age;
  6. char name[50];
  7. } Person;
  8.  
  9. Person newperson(char *name, int age)
  10. {
  11. Person temp;
  12. strcpy(temp.name, name);
  13. temp.age = age;
  14. return temp;
  15. }
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 271
Reputation: fatihpiristine has a little shameless behaviour in the past 
Solved Threads: 16
fatihpiristine's Avatar
fatihpiristine fatihpiristine is offline Offline
Posting Whiz in Training
 
0
  #4
Nov 4th, 2009
thanks for the remark. that was the thing i was trying to remember.
Do a favour, leave me alone
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC