944,134 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Marked Solved
  • Views: 685
  • C RSS
Nov 4th, 2009
0

left operand must be l-value

Expand Post »
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. }
Similar Threads
Reputation Points: 6
Solved Threads: 19
Posting Whiz in Training
fatihpiristine is offline Offline
283 posts
since Sep 2007
Nov 4th, 2009
0
Re: left operand must be l-value
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. }
Reputation Points: 6
Solved Threads: 19
Posting Whiz in Training
fatihpiristine is offline Offline
283 posts
since Sep 2007
Nov 4th, 2009
0
Re: left operand must be l-value
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. }
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Nov 4th, 2009
0
Re: left operand must be l-value
thanks for the remark. that was the thing i was trying to remember.
Reputation Points: 6
Solved Threads: 19
Posting Whiz in Training
fatihpiristine is offline Offline
283 posts
since Sep 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: raw sockets using mac addresses
Next Thread in C Forum Timeline: How to produce an assembly file (.asm) on Windows by program in C





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC