473,387 Members | 1,578 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.

structure and pointer

63
#include <stdio.h>

typedef struct exam ex;
struct exam {
int val;
};

int main() {
int aa;
ex user;
ex *ex_ptr;

printf("\n value ");
scanf("%d", &(ex_ptr->val));
ex_ptr = &user;
printf("%d",*(int *)aa= (ex_ptr->val));

}

iam trying to assign the value "val" to the integer aa.
But segmentation fault arises ...pls help
Jun 5 '07 #1
5 1271
weaknessforcats
9,208 Expert Mod 8TB
On line 14 you are using ex_ptr before you put an address in it:

Expand|Select|Wrap|Line Numbers
  1. scanf("%d", &(ex_ptr->val));
  2.  
Jun 5 '07 #2
askcq
63
yes changed it ...but again the same error occurs
Jun 6 '07 #3
gpraghuram
1,275 Expert 1GB
HI,
Allocate memory for the pointer and the call scanf.
Expand|Select|Wrap|Line Numbers
  1. ex *ex_ptr=(struct exam*)malloc(sizeof(struct exam)); ///Add this line
  2.  
  3. printf("\n value ");
  4. scanf("%d", &(ex_ptr->val));
  5.  
  6.  
Thanks
Raghuram
Jun 6 '07 #4
askcq
63
yes....but still it shows error ...
Jun 12 '07 #5
weaknessforcats
9,208 Expert Mod 8TB
yes....but still it shows error ...
Not when I ran this code:
Expand|Select|Wrap|Line Numbers
  1. ex *ex_ptr=(struct exam*)malloc(sizeof(struct exam)); ///Add this line
  2.  
  3. printf("\n value ");
  4. scanf("%d", &(ex_ptr->val));
  5. printf("You entered %d\n", ex_ptr->val);
  6.  
  7.     }
  8.  
Jun 12 '07 #6

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

Similar topics

7
by: Jake Thompson | last post by:
Hello I created a DLL that has a function that is called from my main c program. In my exe I first get a a pointer to the address of the function by using GetProcAddress and on the dll side I...
3
by: Michael | last post by:
Hi, I have had a look in the FAQ but cannot see anything related, of course that doesn't mean it's not there. In any case: I have the following: void function(){ struct tm *time2;
8
by: SP | last post by:
The following code crashes after I add the two nested FOR loops at the end, I am starting to learn about pointers and would like to understand what I'm doing wrong. I think the problem is the way...
20
by: dspfun | last post by:
I've come a across a program that declares the following data structure. typedef struct node { struct node *next; } node; It looks like a recursive data structure but I'm having trouble...
7
by: ot_007_2001 | last post by:
Hi, all, For pricticing defination of structure in C, I wrote a small code as follow: #include<stdio.h> struct datastruct { int data;
5
by: zehra.mb | last post by:
Hi, I had written application for storing employee data in binary file and reading those data from binary file and display it in C language. But I face some issue with writing data to binary file....
14
by: deepak | last post by:
Hi Experts, I'm getting this compilation error while trying to access a member in structure. at what time we will get this error message? Thanks, Deepak
5
by: =?Utf-8?B?QXlrdXQgRXJnaW4=?= | last post by:
Hi Willy, Thank you very much for your work. C++ code doesnot make any serialization. So at runtime C# code gives an serialization error at "msg_file_s sa = (msg_file_s) bf.Deserialize(ms);"...
10
by: Scott Townsend | last post by:
So I need to talk to a devices that expects all of the bits and bytes I sent it to be in specific places (not yet 100% defined). I wanted to create a structure/class with all of the data in it...
25
by: jbholman | last post by:
I am pretty new to C and doing my first project in C. I actually read almost the entire FAQ, but can't seem to figure out this problem. I have a structure. I have a list of these structures. ...
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: 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
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?
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
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...

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.