#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Location
    Sweden, LKPG
    Posts
    3
    Rep Power
    0

    Code is segfault:ing


    Been awhile since I coded in C and can't seem to find the problem in this small test program. The resault is when running the program a big nice segfault.

    PHP Code:
    #include <stdio.h>

    int main() {
      
    FILE *file;
      
    int *width, *height, *bitsPerPixel;
      
    char *check;

      
    file fopen("test.bmp""rb");

      
    fseek(file18SEEK_SET);
      
    fread(width41file); 
      
    fread(height41file);
      
    fseek(file2SEEK_CUR);
      
    fread(bitsPerPixel41file); 
      
    fseek(file22SEEK_CUR);
      
    fread(check11file);

      
    printf("%ix%ix%i\n", *width, *height, *bitsPerPixel);
      
    printf("Red: %i", *check);

      
    fclose(file);
      
      return 
    0;

    What am I doing wrong ?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Posts
    272
    Rep Power
    19
    Your width, height, bitsperpixel, and check variables are all pointers that have not been initialized to point to valid memory locations.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Location
    Sweden, LKPG
    Posts
    3
    Rep Power
    0

    Talking


    well..that was a really stupid mistake :mad:

IMN logo majestic logo threadwatch logo seochat tools logo