473,399 Members | 3,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

assigning values to C++ structures

I have declared an char array in my structure.After creating instance of the structure,i initialized its members in following way.

structure student
{
char name[20];
int marks;
}

int main()
{
student s1;
s1.name = "abcd";
// some more statements..
}

this code gives me compilation error as "lvalue required in function main "
but when i assign the value by a cin
i.e cin>>s1.name ;
the program is not giving any error statements

Can anyone please explain me why??
Jan 2 '08 #1
2 2380
gpraghuram
1,275 Expert 1GB
I have declared an char array in my structure.After creating instance of the structure,i initialized its members in following way.

structure student
{
char name[20];
int marks;
}

int main()
{
student s1;
s1.name = "abcd";
// some more statements..
}

this code gives me compilation error as "lvalue required in function main "
but when i assign the value by a cin
i.e cin>>s1.name ;
the program is not giving any error statements

Can anyone please explain me why??
Hi,
There is a ; missing in the code aat the end of the struct declaration.
Also when you are assigning value to a character arry you want to do a strcpy and not an assignment.
NOTE
Please use code tags while posting your question.

Raghuram
Jan 2 '08 #2
manjuks
72
Hi,

You have used character array in structure. And in main you are trying to assign string to that array. You will get error since you cant assign string constant to that array, you can do so by using pointers.

Thanks,
Manju
Jan 2 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Dave | last post by:
I am trying to create a function in SQL 2000. Im rusty on function syntax and need to also assign some variables for use within this function. Example: create function blah (@param1 int) ...
6
by: steveneng | last post by:
C++ Primer Plus Programming Exercises 4th Ed - Prate Help I'm trying to refresh myself and I'm stuck on this problem (not homework/school related but for personal advancement). 6: Do...
16
by: BigMan | last post by:
How can I check if assignment of a float to a double (or vice versa) will result in loss of precision?
6
by: Pushkar Pradhan | last post by:
I have a struct like this: struct point { int x; int y; }; Then I need to assign a certain point "=" another pt. eg. struct point p1, pArr;
14
by: Eric Bantock | last post by:
Very basic question I'm afraid. Once an array has been declared, is there a less tedious way of assigning values to its members than the following: myarray=8; myarray=3; myarray=4; myarray=0;...
8
by: Ricardo Sta. Rita | last post by:
Hello people, We have been dealing with for a long time now. It's a bit weird for a newcomer like us so we decided to ask the geniuses here. C# doesn't seem to be assigning values, consider...
9
by: Thiru .Net | last post by:
how to assign unsigned values in vb.net i have a statement like this in c# public const uint FEEDER = 0x00000001; when i tried to convert above into vb.net i said Public Const FEEDER As...
0
by: ryoung | last post by:
I receive the following error when I attempt to assign values to a web service array. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. ...
37
by: miken32 | last post by:
In PHP, if a function returns an array it's fairly common to capture its return values like this: <?php list($foo, $bar, $baz) = some_function_that_return_an_array(); ?> In Javascript, would...
9
Catalyst159
by: Catalyst159 | last post by:
I have a form which is used to calculate residential Floor Area Ratio (FAR). The form is structured into seven parts as follows: Part A: Maximum FAR and Floor Area: Part B: Gross Floor Area of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.