Thread: Segmentation Fault Help

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    55

    Segmentation Fault Help

    Code:
    #include<stdio.h>
    #include<stdlib.h>
    
    int main()
    
    {
    
    FILE *ofp;
    
    ofp = fopen("Cards.dat", "r");
    
    if (ofp == NULL)
    {
     printf("Unable to open Cards.dat");
    }
    
    int numbers[10][2];
    int r, c, n;
    
    for (r = 0; r < 100; ++r)
       {
       for(c = 0; c < 2; ++c)
          {
          fscanf(ofp, "%d", &n);
          numbers[r][c] = n;
          }
       }
    
    printf("%d\n", numbers[0][0]);
    
    
    
    
    
    return 0;
    
    }
    I can't find why it's giving me a segmentation fault error

    Here's the file it's pulling from...
    Code:
    1 4
    11 3
    4 2
    0 0

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Your r had better not go over 10.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Segmentation fault
    By bennyandthejets in forum C++ Programming
    Replies: 7
    Last Post: 09-07-2005, 05:04 PM
  2. Segmentation fault
    By NoUse in forum C Programming
    Replies: 4
    Last Post: 03-26-2005, 03:29 PM
  3. Locating A Segmentation Fault
    By Stack Overflow in forum C Programming
    Replies: 12
    Last Post: 12-14-2004, 01:33 PM
  4. Annoying Segmentation Fault
    By Zildjian in forum C++ Programming
    Replies: 7
    Last Post: 10-08-2004, 02:07 PM
  5. Segmentation fault...
    By alvifarooq in forum C++ Programming
    Replies: 14
    Last Post: 09-26-2004, 12:53 PM

Tags for this Thread