Sponsored Content
Top Forums Programming why I am gettin a segmentation fault when using pointers Post 302166838 by user_prady on Wednesday 13th of February 2008 01:01:09 AM
Old 02-13-2008
New problem using pointer in structure

Quote:
Originally Posted by Franklin52
You must assign the address of the variable to the pointer this way:

Code:
input_re_see = &input_re;

instead of:

Code:
*input_re_see = input_re;

Google on "pointers tutorial".

Regards
You are right ,,Now I am getting , but the problem again comes when I am trying to use a structure..
I am doing the following

Code:
typedef unsigned int U;
typedef struct {U c; U d;} vec32;
 
FILE* fileopen();
void read_line(FILE *);
 
void read_line(FILE *fh){
  char s[100];
  double input_re, input_im, *input_re_tmp, *input_im_tmp;
  U lsts, vgagain;
  U *lsts_tmp, *vgagain_tmp;
  
//vec32 *lsts_str, *vgagain_str;

   if( fgets(s,sizeof(s),fh) != NULL) {
     sscanf(s,"%lf %lf %u %u \n",&input_re, &input_im, &lsts, &vgagain);

     input_re_tmp   = &input_re;
     input_im_tmp   = &input_im;
     lsts_tmp          = &lsts;
     vgagain_tmp     =&vgagain_tmp;

    //   lsts_str->d     = &lsts;
    //   vgagain_str->d    = &vgagain;
    
 
     printf(" %f %f %u %u \n  ", *input_re_tmp, *input_im_tmp, *lsts_tmp, *vgagain_tmp);
     //printf(" %f %f %u %u %u %u %u %u \n  ", *input_re_tmp, *input_im_tmp, lsts_str->d, vgagain_str->d);
 
    }
}
FILE* fileopen(){
          void *file = fopen("abc.txt", "r");
            return file;
}
int main(void) {
 
           FILE *fh;
           int i;
              fh = fileopen();
              for(i =0;i < 5 ; i++){
                 read_line(fh);
              }
 
              return 0;
}

My Input file (abc.txt) is as follows
Code:
 5.08107 14.1132 0 71 
 -0.941856 14.9704 0 71 
 -6.80986 13.3651 0 71

Why I am getting a segmentation fault when I removing the commented lines.. Please I am elementary to pointer to structure , so If I am making some mistakes Please suggest me ..

Thanks in advance...

Regards,
Prady
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Segmentation Fault

hello all, I tried a program on an array to intialise array elements from the standard input device.it is an integer array of 5 elements.but after entering the 4th element it throws a message called "Segmentation Fault" and returns to the command prompt without asking for the 5th element. ... (3 Replies)
Discussion started by: compbug
3 Replies

2. AIX

Segmentation fault

Hi , During execution a backup binary i get following error "Program error 11 (Segmentation fault), saving core file in '/usr/datatools" Riyaz (2 Replies)
Discussion started by: rshaikh
2 Replies

3. Programming

Why not a segmentation fault??

Hi, Why I don't receive a segmentation fault in the following sample. int main(void) { char buff; sprintf(buff,"Hello world"); printf("%s\n",buff); } If I define a buffer of 10 elements and I'm trying to put inside it twelve elements, Should I receive a sigsev... (22 Replies)
Discussion started by: lagigliaivan
22 Replies

4. UNIX for Dummies Questions & Answers

Segmentation Fault

Hi, While comparing primary key data of two tables thr bteq script I am getting this Error. This script is a shell script. *** Error: The following error was encountered on the output file. Script.sh: 3043492 Segmentation fault(coredump) Please let me know how to get through it. ... (5 Replies)
Discussion started by: monika
5 Replies

5. Programming

Segmentation fault in C

i have this code int already_there(char *client_names, char *username) { int i; for(i = 0; i<NUM; i++) { printf("HERE\n"); if (strcmp(client_names, username)==0) return(1); } return(0); } and i get a segmentation fault, whats wrong here? (7 Replies)
Discussion started by: omega666
7 Replies

6. UNIX for Advanced & Expert Users

segmentation fault with ps

What does this mean and why is this happening? $ ps -ef | grep ocular Segmentation fault (core dumped) $ ps -ef | grep ocular Segmentation fault (core dumped) $ ps aux | grep ocular Segmentation fault (core dumped) $ ps Segmentation fault (core dumped) $ pkill okular $ ps... (1 Reply)
Discussion started by: cokedude
1 Replies

7. UNIX for Dummies Questions & Answers

Segmentation fault

#include<stdio.h> #include<malloc.h> #include<unistd.h> #include<stdlib.h> void *start_1(void *argv) { printf("thread 0x%x\n",(unsigned int)pthread_self()); pthread_exit((void*)1); } void *start_2(void *argv) { printf("thread 0x%x\n",(unsigned int)pthread_self()); return (void*)2; }... (2 Replies)
Discussion started by: vincent__tse
2 Replies

8. Programming

Using gdb, ignore beginning segmentation fault until reproduce environment segmentation fault

I use a binary name (ie polo) it gets some parameter , so for debugging normally i do this : i wrote script for watchdog my app (polo) and check every second if it's not running then start it , the problem is , if my app , remain in state of segmentation fault for a while (ie 15 ... (6 Replies)
Discussion started by: pooyair
6 Replies

9. Programming

Segmentation fault

I keep getting this fault on a lot of the codes I write, I'm not exactly sure why so I'd really appreciate it if someone could explain the idea to me. For example this code #include <stdio.h> main() { unsigned long a=0; unsigned long b=0; int z; { printf("Enter two... (2 Replies)
Discussion started by: sizzler786
2 Replies

10. Programming

C. To segmentation fault or not to segmentation fault, that is the question.

Oddities with gcc, 2.95.3 for the AMIGA and 4.2.1 for MY current OSX 10.14.1... I am creating a basic calculator for the AMIGA ADE *NIX emulator in C as it does not have one. Below are two very condensed snippets of which I have added the results inside the each code section. IMPORTANT!... (11 Replies)
Discussion started by: wisecracker
11 Replies
TV_SORT(1p)						User Contributed Perl Documentation					       TV_SORT(1p)

NAME
tv_sort - Sort XMLTV listings files by date, and add stop times. SYNOPSIS
tv_sort [--help] [--by-channel] [--output FILE] [FILE...] DESCRIPTION
Read XMLTV data and write out the same data sorted in date order. Where stop times of programmes are missing, guess them from the start time of the next programme on the same channel. For the last programme of a channel, no stop time can be added. Tv_sort also performs some sanity checks such as making sure no two programmes on the same channel overlap. --output FILE write to FILE rather than standard output --by-channel sort first by channel id, then by date within each channel. --duplicate-error If the input contains the same programme more than once, consider this as an error. Default is to silently ignore duplicate entries. The time sorting is by start time, then by stop time. Without --by-channel, if start times and stop times are equal then two programmes are sorted by internal channel id. With --by-channel, channel id is compared first and then times. You can think of tv_sort as converting XMLTV data into a canonical form, useful for diffing two files. EXAMPLES
At a typical Unix shell or Windows command prompt: tv_sort <in.xml >out.xml tv_sort in.xml --output out.xml These are different ways of saying the same thing. AUTHOR
Ed Avis, ed@membled.com perl v5.14.2 2006-03-02 TV_SORT(1p)
All times are GMT -4. The time now is 09:25 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy