473,508 Members | 2,079 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

nested structure

8 New Member
hi this is the code that i have but i seem to have 2 errors and i dont understand were they are so can some one please help me. thanks

this is the code
#include<iostream.h>
#include<conio.h>

struct faculty
{
char fact1;
char fact2;
char fact3;
};

struct dean
{
char dean1;
char dean2;
char dean3;
};

struct seniorlecture
{
char seniorlec1;
char seniorlec2;
char seniorlec3;
};

struct secretary
{
char sec1;
};

void main()
{

faculty uni;
dean uni2;
seniorlecture uni3;
secretary uni4;

uni.fact1='business';
uni.fact2='law';
uni.fact3='engineering';

uni2.dean1='john';
uni2.dean2='sara';
uni2.dean3='jane';

uni3.seniorlec1='sam';
uni3.seniorlec2='pat';
uni3.seniorlec3='tom';

uni4.sec1='kate';

cout<< "Faculty is:"<<uni.fact1<<endl;
cout<< "Dean of department is:"<<uni2.dean1<<endl;
cout<< "Senior lecture of department is:"<<uni3.seniorlec1<<endl;
cout<< "Secretary of department is:"<<uni4.sec1<<endl;

cout<< "Faculty is:"<<uni.fact2<<endl;
cout<< "Dean of department is:"<<uni2.dean2<<endl;
cout<< "Senior lecture of department is:"<<uni3.seniorlec2<<endl;
cout<< "Secretary of department is:"<<uni4.sec1<<endl;

cout<< "Faculty is:"<<uni.fact3<<endl;
cout<< "Dean of department is:"<<uni2.dean3<<endl;
cout<< "Senior lecture of department is:"<<uni3.seniorlec3<<endl;
cout<< "Secretary of department is:"<<uni4.sec1<<endl;
}

getche();


and this is the error message that i have

[too many characters in constant]
Nov 5 '06 #1
14 5204
aarthy82
4 New Member
struct faculty
{
char fact1;
char fact2;
char fact3;
};
faculty uni;
uni.fact1='business';
uni.fact2='law';
uni.fact3='engineering';
Hi There,
According to the declaration above you have a structure named faculty which has three members. Those members are of type character (i.e) it can hold only one character at a time. for (e.g) you can store uni.fact1='a';
So if you want to store a array of characters in fact1 you have to decalre fact1 as character array as
char fact1[50];
now
strcpy(uni.fact,"Business"); will work.
Try this. If you have any problem do let me know,
Thanks and Regards,
Aarthy.
Nov 5 '06 #2
ser
8 New Member
could you show me what you mean as it is the first time i'm using c++ and i dont understand how i'm going to add the changes that you have told me to put in the program.
thanks
Nov 5 '06 #3
aarthy82
4 New Member
could you show me what you mean as it is the first time i'm using c++ and i dont understand how i'm going to add the changes that you have told me to put in the program.
thanks
Here goes the program,

#include<iostream.h>
#include<conio.h>

struct faculty
{
char fact1[50];
char fact2[50];
char fact3[50];
};

struct dean
{
char dean1[50];
char dean2[50];
char dean3[50];
};

struct seniorlecture
{
char seniorlec1[50];
char seniorlec2[50];
char seniorlec3[50];
};

struct secretary
{
char sec1[50];
};

void main()
{

faculty uni;
dean uni2;
seniorlecture uni3;
secretary uni4;

strcpy(uni.fact1,"business");
strcpy(uni.fact2,"law");
strcpy(uni.fact3,"engineering");

strcpy(uni2.dean1,"john");
strcpy(uni2.dean2,"sara");
strcpy(uni2.dean3,"jane");

strcpy(uni3.seniorlec1,"sam");
strcpy(uni3.seniorlec2,"pat");
strcpy(uni3.seniorlec3,"'tom");

strcpy(uni4.sec1,"kate");

cout<< "Faculty is:"<<uni.fact1<<endl;
cout<< "Dean of department is:"<<uni2.dean1<<endl;
cout<< "Senior lecture of department is:"<<uni3.seniorlec1<<endl;
cout<< "Secretary of department is:"<<uni4.sec1<<endl;

cout<< "Faculty is:"<<uni.fact2<<endl;
cout<< "Dean of department is:"<<uni2.dean2<<endl;
cout<< "Senior lecture of department is:"<<uni3.seniorlec2<<endl;
cout<< "Secretary of department is:"<<uni4.sec1<<endl;

cout<< "Faculty is:"<<uni.fact3<<endl;
cout<< "Dean of department is:"<<uni2.dean3<<endl;
cout<< "Senior lecture of department is:"<<uni3.seniorlec3<<endl;
cout<< "Secretary of department is:"<<uni4.sec1<<endl;
}

getch();

So compile the above program and see the result. I have changed the declaration part. Basically in C and c++ you can't assign strings using equal to sign. You have to use strcpy function. Hope this helps you,
Aarthy.
Nov 5 '06 #4
ser
8 New Member
i had done what you said and used your program i had more errors then before one of the errors was saying that i can not use the stycp so i took it out and have still 2 errors on both errors it says the following

error C2015: too many characters in constant
Nov 5 '06 #5
ser
8 New Member
can someone please help i can not solve this error
Nov 6 '06 #6
Banfa
9,065 Recognized Expert Moderator Expert
I am betting where aarthy82 had

"business"

in their code you still have

'business'

as per your original code. "business" is a string constant and can contain any number of printable characters, where as '...' signifies a character constant and can only contain a single character, i.e. 'b' so 'business' has too many characters in it for a character constant.
Nov 6 '06 #7
ser
8 New Member
i understand whta you are saying but how can i put it in the code.????
Nov 6 '06 #8
ser
8 New Member
i have added some changes but i have know got more errors then before i need help asap as i have to hand this in tommorow. this is teh code that i have so far and i have been trying but i just dont get this c++
[code]
#include<iostream>
#include <string>

struct faculty
{
string fact1;
string fact2;
string fact3;
};

struct dean
{
string dean1;
string dean2;
string dean3;
};

struct seniorlecture
{
string seniorlec1;
string seniorlec2;
string seniorlec3;
};

struct secretary
{
string sec1;
};

int main()
{

faculty uni;
dean uni2;
seniorlecture uni3;
secretary uni4;

uni.fact1="business";
uni.fact2 ="law";
uni.fact3 ="engineering";

uni2.dean1 ="john";
uni2.dean2 ="sara";
uni2.dean3 ="jane";

uni3.seniorlec1 = "sam";
uni3.seniorlec2 ="pat";
uni3.seniorlec3 ="tom";

uni4.sec1 ="kate";

cout<< "Faculty is:"<<uni.fact1<<endl;
cout<< "Dean of department is:"<<uni2.dean1<<endl;
cout<< "Senior lecture of department is:"<<uni3.seniorlec1<<endl;
cout<< "Secretary of department is:"<<uni4.sec1<<endl;

cout<< "Faculty is:"<<uni.fact2<<endl;
cout<< "Dean of department is:"<<uni2.dean2<<endl;
cout<< "Senior lecture of department is:"<<uni3.seniorlec2<<endl;
cout<< "Secretary of department is:"<<uni4.sec1<<endl;

cout<< "Faculty is:"<<uni.fact3<<endl;
cout<< "Dean of department is:"<<uni2.dean3<<endl;
cout<< "Senior lecture of department is:"<<uni3.seniorlec3<<endl;
cout<< "Secretary of department is:"<<uni4.sec1<<endl;
}

return0
Nov 8 '06 #9
sicarie
4,677 Recognized Expert Moderator Specialist
ser-

From what I can see, there are only three minor syntax issues with your completed code.

1) the includes

You declare the two includes, and you don't specify a namespace. Merely put underneath those two
Expand|Select|Wrap|Line Numbers
  1. using namespace std;
  2.  
2) brackets

Any loops you create should have matching { } brackets. Whenever I code, if I'm going to do a for loop, for instance, I start with for () { } just so I don't forget them. You have a closing bracket for your main() routine above the return 0.


3) statement closure

All complete statements (aside of loops), should have a ';' finishing them off. You left this off on the return 0

Expand|Select|Wrap|Line Numbers
  1.     return 0;
  2. }
  3.  
And your code should compile and print.
Nov 8 '06 #10
ser
8 New Member
can someone help this code i just dont understand how i'm going to make the code work i have tried another way but i have some errors and i dont understand what i'm doing wrong.
[code]
#include<iostream.h>
#include<conio.h>


struct faculty
{
char fact1;
char fact2;
char fact3;
};

struct dean
{
char dean1;
char dean2;
char dean3;
};

struct seniorlecture
{
char seniorlec1;
char seniorlec2;
char seniorlec3;
};

struct secretary
{
char sec1;
};

int main()
{

faculty uni;
dean uni2;
seniorlecture uni3;
secretary uni4;

uni.fact1="business";
uni.fact2 ="law";
uni.fact3 ="engineering";

uni2.dean1 ="john";
uni2.dean2 ="sara";
uni2.dean3 ="jane";

uni3.seniorlec1 = "sam";
uni3.seniorlec2 ="pat";
uni3.seniorlec3 ="tom";

uni4.sec1 ="kate";

cout<< "Faculty is:"<<uni.fact1<<endl;
cout<< "Dean of department is:"<<uni2.dean1<<endl;
cout<< "Senior lecture of department is:"<<uni3.seniorlec1<<endl;
cout<< "Secretary of department is:"<<uni4.sec1<<endl;

cout<< "Faculty is:"<<uni.fact2<<endl;
cout<< "Dean of department is:"<<uni2.dean2<<endl;
cout<< "Senior lecture of department is:"<<uni3.seniorlec2<<endl;
cout<< "Secretary of department is:"<<uni4.sec1<<endl;

cout<< "Faculty is:"<<uni.fact3<<endl;
cout<< "Dean of department is:"<<uni2.dean3<<endl;
cout<< "Senior lecture of department is:"<<uni3.seniorlec3<<endl;
cout<< "Secretary of department is:"<<uni4.sec1<<endl;

}
getche();
Nov 8 '06 #11
sicarie
4,677 Recognized Expert Moderator Specialist
Ok, this is where "reading" comes in handy. I told you the three things that were wrong with your code, just go back and look at them. You didn't even fix the one where I told you what to put and where. I don't know what getche() is, but it should be return 0;
Nov 8 '06 #12
ser
8 New Member
dont worry i had to think abit and i have sorted it out so thanks for your help i have now finished the program and it works. thanks again
Nov 8 '06 #13
vivek2417
1 New Member
hi this is the code that i have but i seem to have 2 errors and i dont understand were they are so can some one please help me. thanks

this is the code
#include<iostream.h>
#include<conio.h>

struct faculty
{
char fact1;
char fact2;
char fact3;
};

struct dean
{
char dean1;
char dean2;
char dean3;
};

struct seniorlecture
{
char seniorlec1;
char seniorlec2;
char seniorlec3;
};

struct secretary
{
char sec1;
};

void main()
{

faculty uni;
dean uni2;
seniorlecture uni3;
secretary uni4;

uni.fact1='business';
uni.fact2='law';
uni.fact3='engineering';

uni2.dean1='john';
uni2.dean2='sara';
uni2.dean3='jane';

uni3.seniorlec1='sam';
uni3.seniorlec2='pat';
uni3.seniorlec3='tom';

uni4.sec1='kate';

cout<< "Faculty is:"<<uni.fact1<<endl;
cout<< "Dean of department is:"<<uni2.dean1<<endl;
cout<< "Senior lecture of department is:"<<uni3.seniorlec1<<endl;
cout<< "Secretary of department is:"<<uni4.sec1<<endl;

cout<< "Faculty is:"<<uni.fact2<<endl;
cout<< "Dean of department is:"<<uni2.dean2<<endl;
cout<< "Senior lecture of department is:"<<uni3.seniorlec2<<endl;
cout<< "Secretary of department is:"<<uni4.sec1<<endl;

cout<< "Faculty is:"<<uni.fact3<<endl;
cout<< "Dean of department is:"<<uni2.dean3<<endl;
cout<< "Senior lecture of department is:"<<uni3.seniorlec3<<endl;
cout<< "Secretary of department is:"<<uni4.sec1<<endl;
}

getche();


and this is the error message that i have

[too many characters in constant]
i think the error is because u cannot have more than 2 chars in a char variable.
Aug 26 '07 #14
gsi
51 New Member
Hi,
i think the error is because u cannot have more than 2 chars in a char variable.
A variable of data type ' char ' can never hold more than one character, Internally the character itself is represented as an integer constant (Its corresponding Ascii code as an integer constant).

Thanks,
gsi.
Aug 26 '07 #15

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

Similar topics

0
1252
by: Jochen Daum | last post by:
Hi, I have some JS code going like n2 = new something(){ with n2{ __add (a); __add (d); }
0
1144
by: thijs.kupers | last post by:
hy, I don't have so much experience with xslt, so i've got a question about it. I've got a xml-document with the following structure: <Block> <Block> <State name="1">...</State> <State...
1
3064
by: Hazz | last post by:
I have 5 tables in SQL Server. Each with the following design and a sample chain of the relationships from the root (WRL - World) UUS is the 'Code' of the first table and it is the 'Parent' value...
2
5222
by: prakashgkhaire | last post by:
i have two structure where first structure consists val and structure pointer(linklist), 2nd structure consists, val, a varialbe of first structure, pointer of structure. Now i found to pass the...
9
2365
by: Bill Grigg | last post by:
All, Can anyone supply an example or reference to an example of using reflection to determine the data types and array lengths contained in a nested stucture in C#? Actually, it is a structure...
4
2238
by: teddysnips | last post by:
I would like to serialize a class to XML. The format of the XML is fixed (see below). It only needs to be serialized - it is read by another application. I know I can do it manually using...
3
5515
by: acacia314 | last post by:
I'm attempting to read a data file into a array of structures. The data comes like this Jane Doe 5 245-44-8899 September 15, 2005 Number of entries in the file is unknown. My segment to...
2
3288
by: Opteron64 | last post by:
Hi, I'm trying to create and initialise a dynamic array within a nested structure. The structure is defined as followed: (C++ code) typedef unsigned char uchar; typedef unsigned int uint; ...
5
1903
by: bitstreamer | last post by:
Greetings. The emulation fever has conquered all kinds of Internet communities, and hence I've decided to write a tool in C which can read and modify a disk image. (However, I won't tell which...
0
2114
by: sarabonn | last post by:
Hello everyone, Iam using cookcomputing xmlrpc in c#.Net. My server xmlrpc call function is like this api = (('object_id', 'ASCII string', 1), ('services',...
0
7125
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
7328
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7049
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
4709
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3199
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3186
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1561
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
767
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
422
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.