| | |
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
| Thread Tools | Search this Thread |
Tag cloud for C
adobe ansi api array arrays asterisks bash binarysearch calculate centimeter char convert copyanyfile copyimagefile copypdffile cprogramme createcopyoffile csyntax directory dynamic fflush file fork frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators infiniteloop initialization interest km lazy linked linkedlist linux linuxsegmentationfault list locate logical_drives match matrix meter microsoft motherboard multi mysql number open opendocumentformat opensource owf pattern pdf performance pointer pointers posix power problem probleminc program programming pyramidusingturboccodes read recursion recv repetition scanf scheduling scripting segmentationfault send shape socketprograming spoonfeeding stack standard string strings structures suggestions systemcall test testautomation unix user variable voidmain() wab win32api windows.h






