473,401 Members | 2,146 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,401 software developers and data experts.

issue with struct assignment.....

Hi All,

1. How to acess the member name.
2. I am trying to fill the name with "Sanny". Vc++ IDE generates exception
on \return.

3. what is wrong with following assignment.


struct profile
{
int Rid;
char *name;
}emp;

int main()
{
printf("\n Enter the Rid and name");
scanf("%d",&emp.Rid);
scanf("%s",emp.name);
//puts(Danoop->name);
//gets(Danoop.name);
//printf("\n%s",Danoop.name);
return 0;
}
Mar 16 '09 #1
1 1503
donbock
2,426 Expert 2GB
@sanddune008
The 'name' field of the structure is large enough to hold a pointer to a string -- not the string itself. You need to allocate a buffer, copy the string into the buffer, and then put the address of the buffer into the 'name' field.
Mar 16 '09 #2

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

Similar topics

4
by: James Harris | last post by:
Having updated my Debian system it now complains that I am using an incompatible pointer type in warnings such as "passing arg 2 of 'bind' from incompatible pointer type" from code, struct...
2
by: Immo Birnbaum | last post by:
Hi, I'm trying to solve a programming lab assignment for my college C programming course, but as they taught us two semesters of Java before teaching us any C, I'm having problems with all the...
18
by: ranjeet.gupta | last post by:
Dear ALL As we know that when we declare the union then we have the size of the union which is the size of the highest data type as in the below case the size should be 4 (For my case and...
9
by: gamehack | last post by:
Hello all again, Sorry for troubling you with my problems. I've tried to implement simple double linked lists, here's my structure: struct DResult { double val; char* title; struct DResult*...
28
by: WaterWalk | last post by:
Hi, I'm haunted by 2 questions about struct copy. Though I searched the net, but still in confusion. 1. Does struct assignment copies every member including array members? For example, struct...
5
by: Hallvard B Furuseth | last post by:
Does struct assignment copy padding bytes? Some compilers do, but I couldn't find anything in the standard which says they must. What I need is for any padding bytes to contan initialized values...
3
by: VirGin | last post by:
I am passing an object by reference to a function that is supposed to populate it with current data. Both the destination object and the source have nested std::lists, some branches of the lists...
24
by: Grey Alien | last post by:
If I have the ff struct: struct A { unsigned int i; char s; } a, b; And use them in code like this:
5
by: Alexander Adam | last post by:
Hi! I've got this issue: I have a struct like this: struct node { unsigned int m_code; ?? m_data; unsigned int m_data_size; };
1
by: Tom Baxter | last post by:
Hi All, I was hoping someone could clarify something I read in the C# Language Spec regarding "Definite Assignment" of structs. This is a very subtle point. I am referring to ECMA-334, section...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
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
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
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
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.