Coding Villa Forum
FAQs
Advertisements

Explain compilation error Lvalue required in main function in C

Iram Online 4/3/2012 3:24:52 PM

Hello Friends!

I have write following program in C.

main()
{
static char names[5][20]={"pascal","ada","cobol","fortran","perl"};
int i;
char *t;
t=names[3];
names[3]=names[4];
names[4]=t;
for (i=0;i<=4;i++)
printf("%s",names[i]);
}

But it is showing a compile time error Lvalue required in main function. I am not understanding the error message. Please friends explain that problem and write its solution.

Thanks

Share with Friends

Advertisements

Answer

srini Online 8/2/2012 8:31:36 PM

hi,
u can't copy a string directly to another string in c directly. u need to use strcpy .
U can do in java... ;)

Lvalue required explanation:
in ur prog, u r assigning names[4] address value to names[3] address value...
it's like assigning an integer to another integer , for example 5=9; it'll show l value required... likewise u r getting the same error..

hope now u understood... :)
Share with Friends

Post reply

 

Enter This Code
Captcha
 

Subscribe

Email me when people reply


Subscribe to the