473,666 Members | 2,238 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<iostre am.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='busi ness';
uni.fact2='law' ;
uni.fact3='engi neering';

uni2.dean1='joh n';
uni2.dean2='sar a';
uni2.dean3='jan e';

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

uni4.sec1='kate ';

cout<< "Faculty is:"<<uni.fact1 <<endl;
cout<< "Dean of department is:"<<uni2.dean 1<<endl;
cout<< "Senior lecture of department is:"<<uni3.seni orlec1<<endl;
cout<< "Secretary of department is:"<<uni4.sec1 <<endl;

cout<< "Faculty is:"<<uni.fact2 <<endl;
cout<< "Dean of department is:"<<uni2.dean 2<<endl;
cout<< "Senior lecture of department is:"<<uni3.seni orlec2<<endl;
cout<< "Secretary of department is:"<<uni4.sec1 <<endl;

cout<< "Faculty is:"<<uni.fact3 <<endl;
cout<< "Dean of department is:"<<uni2.dean 3<<endl;
cout<< "Senior lecture of department is:"<<uni3.seni orlec3<<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 5216
aarthy82
4 New Member
struct faculty
{
char fact1;
char fact2;
char fact3;
};
faculty uni;
uni.fact1='busi ness';
uni.fact2='law' ;
uni.fact3='engi neering';
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<iostre am.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.fact 1,"business") ;
strcpy(uni.fact 2,"law");
strcpy(uni.fact 3,"engineering" );

strcpy(uni2.dea n1,"john");
strcpy(uni2.dea n2,"sara");
strcpy(uni2.dea n3,"jane");

strcpy(uni3.sen iorlec1,"sam");
strcpy(uni3.sen iorlec2,"pat");
strcpy(uni3.sen iorlec3,"'tom") ;

strcpy(uni4.sec 1,"kate");

cout<< "Faculty is:"<<uni.fact1 <<endl;
cout<< "Dean of department is:"<<uni2.dean 1<<endl;
cout<< "Senior lecture of department is:"<<uni3.seni orlec1<<endl;
cout<< "Secretary of department is:"<<uni4.sec1 <<endl;

cout<< "Faculty is:"<<uni.fact2 <<endl;
cout<< "Dean of department is:"<<uni2.dean 2<<endl;
cout<< "Senior lecture of department is:"<<uni3.seni orlec2<<endl;
cout<< "Secretary of department is:"<<uni4.sec1 <<endl;

cout<< "Faculty is:"<<uni.fact3 <<endl;
cout<< "Dean of department is:"<<uni2.dean 3<<endl;
cout<< "Senior lecture of department is:"<<uni3.seni orlec3<<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<iostre am>
#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="busi ness";
uni.fact2 ="law";
uni.fact3 ="engineerin g";

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.dean 1<<endl;
cout<< "Senior lecture of department is:"<<uni3.seni orlec1<<endl;
cout<< "Secretary of department is:"<<uni4.sec1 <<endl;

cout<< "Faculty is:"<<uni.fact2 <<endl;
cout<< "Dean of department is:"<<uni2.dean 2<<endl;
cout<< "Senior lecture of department is:"<<uni3.seni orlec2<<endl;
cout<< "Secretary of department is:"<<uni4.sec1 <<endl;

cout<< "Faculty is:"<<uni.fact3 <<endl;
cout<< "Dean of department is:"<<uni2.dean 3<<endl;
cout<< "Senior lecture of department is:"<<uni3.seni orlec3<<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

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

Similar topics

0
1260
by: Jochen Daum | last post by:
Hi, I have some JS code going like n2 = new something(){ with n2{ __add (a); __add (d); }
0
1149
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 name="2">...</State>
1
3072
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 of the second table, etc. Parent varchar 3 Name varchar 60 Code varchar 3 WRL United States UUS <- UUS California UCA <- UCA North Coast UNC <- UNC
2
5246
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 variable of 2nd structure to function as variable of 1st structure struct first { int val; struct first *next;
9
2387
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 that I use to communicate to some unmanaged code in a DLL written in C. It is not complicated, but will change and I would like to be able to sequentially access it without explicitly referring to each and every element. Here is the structure:
4
2253
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 XMLTextWriter - e.g. Dim xwriter = New XmlTextWriter("C:\Projects\Formflo\WindowsService\NDde\test.xml", System.Text.Encoding.UTF8) xwriter.Formatting = Formatting.Indented
3
5528
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 read the file is as follows: while( (fscanf(inf, "%s %s %d %s %s %d, %d", arr.fName, arr.lName, arr.gradeLvl, month, arr.date.day,
2
3300
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; struct Results_list {
5
1905
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 kind of disk images until it's finished. Only problem I have now, where do I start and where do I have to malloc() and where not? It's better to know about this in the concept phase, for when the tool goes beyond the magical 1000-lines extent, it...
0
2130
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', 'struct', 0, )]), ('reset', 'boolean', 0)) the first object is a string i can pass a as string. how can create a nested structure for the second argument and pass it ?..
0
8440
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8355
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8781
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8550
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7381
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6191
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4365
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2769
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 we have to send another system
2
1769
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.