C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 28th, 2003, 06:24 PM
nempo nempo is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2002
Location: Sweden, LKPG
Posts: 3 nempo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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 ?

Reply With Quote
  #2  
Old June 28th, 2003, 09:25 PM
3dfxMM 3dfxMM is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 266 3dfxMM User rank is Sergeant (500 - 2000 Reputation Level)3dfxMM User rank is Sergeant (500 - 2000 Reputation Level)3dfxMM User rank is Sergeant (500 - 2000 Reputation Level)3dfxMM User rank is Sergeant (500 - 2000 Reputation Level)3dfxMM User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 21 h 19 m 28 sec
Reputation Power: 13
Your width, height, bitsperpixel, and check variables are all pointers that have not been initialized to point to valid memory locations.

Reply With Quote
  #3  
Old June 29th, 2003, 06:34 AM
nempo nempo is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2002
Location: Sweden, LKPG
Posts: 3 nempo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Talking

well..that was a really stupid mistake

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Code is segfault:ing


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT