Sponsored Content
Top Forums Programming why I am gettin a segmentation fault when using pointers Post 302165513 by user_prady on Friday 8th of February 2008 03:55:39 AM
Old 02-08-2008
Power why I am gettin a segmentation fault when using pointers

Hello Friends,

Here is my programme.
Code:
#include <stdio.h>
 
FILE* fileopen();
void read_line(FILE*);
  
void read_line(FILE *fh){
              char s[200];
              double *input_re_see, *input_im_see;
              double input_re, input_im;

if( fgets(s,sizeof(s),fh) != NULL) { 
    sscanf(s,"%lf %lf ", &input_re, &input_im);
     
   // *input_re_see = input_re;
   // *input_im_see = input_im;
   // printf("%f  %f ", *input_re_see, *input_im_see);
 
    printf("input_re= %lf, input_im= %lf ", input_re, input_im );
    printf("%s ",s);
  }
}
FILE* fileopen(){ 
          void *file = fopen("real.dat", "r");
        if(file == NULL){
                printf("Error opening file:");
        }
       return file;
}
int main(void) { 
        
           FILE   *fh;
           int i; 
              fh = fileopen();
              for(i =0 ;i < 50 ; i++){
                 read_line(fh);
              }
 
              return 0;
}

I don't why I am gettin segmentation fault when I remove these comments..

WHat I am doing wrong with the pointer that causes segmentation fault,
Please help..

Regards,
Prady

Last edited by user_prady; 02-08-2008 at 05:27 AM..
 

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
ITKSNAP(1)							   User Commands							ITKSNAP(1)

NAME
itksnap - semi-automatic segmentation of structures in 3D images SYNOPSIS
itksnap [options] [grey_image] DESCRIPTION
SNAP provides semi-automatic segmentation of structures in medical images (e.g. magnetic resonance images of the brain) using active con- tour methods, as well as manual delineation and image navigation. Noteworthy features are: * Linked cursor for seamless 3D navigation * Manual segmentation in three orthogonal planes at once * Support for many different 3D image formats, including NIfTI * Support for concurrent, linked viewing and segmentation of multiple images * Limited support for color images (e.g., diffusion tensor maps) * 3D cut-plane tool for fast post-processing of segmentation results OPTIONS
--grey, -g FILE Load greyscale image FILE (optional) --segmentation, -s FILE Load segmentation image FILE --labels, -l FILE Load label description file FILE --rgb FILE Load RGB image FILE (as overlay if combined with -g) AUTHOR
ITK-SNAP was written by Paul A. Yushkevichi, Hui Zhang, Casey Goodlett, Timothy Burke, Nicholas Tustison, Guido Gerig, Silvio Turello, Joachim Schlegel, Gabor Szekely, Chris Wynn, Arun Neelamkavil, David Gregg, Eric Larsen, Sanjay Sthapit, Sean Ho, Ashraf Farrag, Amy Hen- derson, Robin Munesato, Ming Yu, Nathan Moon, Thorsten Scheuermann, Konstantin Bobkov, Nathan Talbert, Yongjik Kim, Pierre Fillard, Daniel S. Fritsch, Stephen R. Aylward This manual page was written by Michael Hanke <michael.hanke@gmail.com>, for the Debian project (but may be used by others). SEE ALSO
Manual and tutorial: http://itksnap.org Michael Hanke April 2010 ITKSNAP(1)
All times are GMT -4. The time now is 01:38 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy