473,387 Members | 1,348 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,387 software developers and data experts.

Why the following program generates segmentation fault?

Hi All

The below tries to fetch the details of the group to which I belongs to. But due to some reason it seg faults.

#include <grp.h>
#include <stdio.h>

main()
{
gid_t gid;
struct group *grp;
grp=getgrgid(gid);
printf("reached\n");
printf("GroupId %d\n", grp->gr_gid);
printf("GroupName %s\n", grp->gr_name);
printf("GroupPassword %s\n", grp->gr_passwd);
}

reached
Segmentation Fault(coredump)

Thanks & Regards
Sathish Kumar
Nov 15 '07 #1
1 1845
mac11
256 100+
if getgrgid() fails it returns NULL and if you try to access a null pointer you die. You never set gid so I bet getgrgid is failing. Try checking grp against NULL.
Nov 15 '07 #2

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

Similar topics

1
by: Justin Tang | last post by:
Hi I am wondering about the segmentation fault in PHP. Namely, I'm running PHP version 4.6.9 on my server right now and when I try to process a large piece of text via textarea(3k+), the resulting...
3
by: I_have_nothing | last post by:
Hi! I am new in C. I got a lots of "Segmentation Fault"s in my code. I guess One possibility is: if " int array_i; " is declard and the code trys to access "array_i", a Segmentation Fault will...
6
by: tigrfire | last post by:
I've been working on a program to try and play a game of Craps, based on a version I found elsewhere - I didn't code the original, but I added a few things such as a balance and wager system. I'm...
3
by: Amar Prakash Tripaithi | last post by:
Hi Friends, I am working on a project of User Interface Class Library. In it, I have to create a class library in "gnu" using c++ and curses library. I am facing problem while I am on the way of...
27
by: Paminu | last post by:
I have a wierd problem. In my main function I print "test" as the first thing. But if I run the call to node_alloc AFTER the printf call I get a segmentation fault and test is not printed! ...
10
by: paytam | last post by:
hi all can you tell me what's the wrong with this code? I use gcc compiler,but when I wanted to use gets() function in my code but it takes a dangerous warning(the gets function is dangerous...
7
by: pycraze | last post by:
I would like to ask a question. How do one handle the exception due to Segmentation fault due to Python ? Our bit operations and arithmetic manipulations are written in C and to some of our...
4
by: Goran | last post by:
Hi all, i have a problem on program termination. At the moment when main() ends my program creates a segmentation fault. #include <libmylib/myObject.h>
8
by: parkskier | last post by:
Ok, so I got a segmentation fault when I tried to run the program I created. I understand what this error means, but I don't know where it is. If someone can quickly look through my code and point...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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...

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.