Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Segmentation fault at bzero

Posted on 2006-11-13
7
Medium Priority
?
940 Views
Last Modified: 2008-03-03
      struct direntry{
            char filename[FILENAME_LEN];
            char ext[EXT_LEN];
            char attr;
            char resv[RESV_LEN];
            char datetime[DT_LEN];
            char startCluster[SCLUSTER_LEN];
            char filesize[FILESIZE_LEN];
      } *dir_entry;
bzero(dir_entry,sizeof(struct direntry));

At the bzero I get segmentation fault, what am I wrong and how to correct it?
0
Comment
Question by:william007
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 1600 total points
ID: 17934457
you did not initialize dir_entry to point to valid memory
you may want
dir_entry = calloc(sizeof(struct direntry));
0
 
LVL 86

Expert Comment

by:jkr
ID: 17935414
Or did you mean to

struct direntry de;

bzero(&de,sizeof(struct direntry));

?
0
 
LVL 1

Assisted Solution

by:Ashwini_pandey
Ashwini_pandey earned 400 total points
ID: 17936323
1.dir_entry is a pointer that is not pointing to any valid memory location.
accessing any struct member using this dir_entry may  cause segmentation fault.
2.plaese tell what bzero(dir_entry,sizeof(struct direntry)) is intended for ?

 
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 2

Expert Comment

by:numansiddique
ID: 17936875
@Ashwini_pandey

bzero initializes the memory area of the structure to zero ( or NULL).  its like using memset as memset((void *)dir_entry,0,sizeof(struct direntry));
0
 
LVL 1

Expert Comment

by:Ashwini_pandey
ID: 17963076
@numansiddique
" bzero initializes the memory area of the structure to zero ( or NULL).  its like using memset as memset((void *)dir_entry,0,sizeof(struct direntry))"

You must allocate memory to dir_entry using statement before calling bzero function
dir_entry = (struct direntry *)malloc(sizeof(struct direntry));


0
 
LVL 9

Author Comment

by:william007
ID: 17970877
Thanks=)
0
 
LVL 2

Expert Comment

by:numansiddique
ID: 17970998
@Ashwini_pandey
thats r8, i agree with you
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question