| | |
left operand must be l-value
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
what's wrong here?
c Syntax (Toggle Plain Text)
typedef struct person { int age; char name[50]; }; int main() { struct person test; test.age = 20; test.name = "Test"; return 0; }
Do a favour, leave me alone
0
#2 Nov 4th, 2009
anyways i fixed it myself
here is the solution
here is the solution c Syntax (Toggle Plain Text)
typedef struct { int age; char *name[50]; } Person; Person newperson(char *name, int age) { Person temp; *temp.name = name; temp.age = age; return temp; } int main() { Person list[50], ttt; list[0] = newperson("Test", 20); *ttt.name = "ASDF"; return 0; }
Do a favour, leave me alone
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:
C Syntax (Toggle Plain Text)
#include <string.h> typedef struct { int age; char name[50]; } Person; Person newperson(char *name, int age) { Person temp; strcpy(temp.name, name); temp.age = age; return temp; }
"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
![]() |
Similar Threads
- compiler won't accept char as xor operand (C++)
- error c2296: '/': "left hand"; :c2297: "right hand" illegal.... (C++)
- '=' : left operand must be l-value (C++)
- AHHHH!! i cant figure this out. (C++)
- '%' illegal, left operand, has type 'double' (C++)
- Pythagorean Triples (C)
Other Threads in the C Forum
- Previous Thread: raw sockets using mac addresses
- Next Thread: How to produce an assembly file (.asm) on Windows by program in C
Views: 333 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for C
#include * append array arrays bash binarysearch changingto char character cm command copyanyfile copypdffile createprocess() database directory drawing dynamic execv feet fgets file floatingpointvalidation fork framework function functions getlogicaldrivestrin givemetehcodez global grade graphics gtkwinlinux histogram homework i/o ide include infiniteloop initialization input interest intmain() iso keyboard kilometer lazy license linked linkedlist linux list looping loopinsideloop. lowest matrix meter microsoft mqqueue oddnumber odf open openwebfoundation overwrite pause pdf pointer pointers posix power process program programming pyramidusingturboccodes read recursion recv recvblocked reversing segmentationfault single socket socketprogramming spoonfeeding standard strchr string student suggestions system test testing threads unix urboc user whythiscodecausesegmentationfault win32api windowsapi






