Thread: Segmentation fault with a file pointer?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Not bad at Crack Attack!
    Join Date
    Aug 2003
    Posts
    45

    Segmentation fault with a file pointer?

    Please scroll down to my last post!!

    I am compiling sucessfully using gcc 3.3 but on running my program seg faults. I have isolated the problem as being to do with an fprintf line which is fine if I replace fptr with stdout, so I think my fopen line is wrong...

    here is a summary of every line containing fptr as graciously supplied by grep:

    Code:
    18-  double x, *cumulative;
    19:  FILE *fptr;
    20-
    --
    31-  m = (int) strtol ( argv[2], NULL, 10 );
    32:  fptr = fopen ( argv[3], "w" );
    33:  if ( fptr == NULL ) {
    34-    printf ( "Unable to open \"%s\" to write.\n", argv[3] );
    --
    155-	fprintf ( stdout, "%d\t%d\t%d\n", i+1, j+1, adjacency[i][j] );
    156:        fprintf ( fptr, "%d\t%d\t%d\n", i+1, j+1, adjacency[i][j] );
    157-      }
    --
    161-
    162:  fclose(fptr);
    163-  return 0;
    Last edited by Matt13; 07-29-2004 at 08:30 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-05-2009, 05:35 AM
  2. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  3. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM