DaemonForums  

Go Back   DaemonForums > Miscellaneous > Programming

Programming C, bash, Python, Perl, PHP, Java, you name it.

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1   (View Single Post)  
Old 17th April 2011
xmorg xmorg is offline
Real Name: Tim Cooper
Fdisk Soldier
 
Join Date: Sep 2010
Location: San Diego
Posts: 56
Thanked 0 Times in 0 Posts
Default C: address of an int in an array in a struct?

This is an SDL program. gr->rcFlora[1] is an SDLRect with members x,y,w,h
Previously gr->rcFlora[1] was just a normal SDLRect that I declared on top of the code block. Now that I moved it into the struct "gr", it causes the program to segfault.

I allocate memory for it in this way

gr = (GameRes *) malloc(sizeof(GameRes));
LoadResources(gr, scrmode);


Inside the LoadResouces Function I can access the variables like so

Code:
printf("Loading broken tower.\n");
  temp = IMG_Load("data/broken_tower.png");
  gr->flora[1] = SDL_DisplayFormatAlpha(temp);
  gr->rcFlora[1].x = 600; gr->rcFlora[1].y = 128;
  printf("Is the value accessible here?-> x= %d\n",gr->rcFlora[1].x); //Here they work but not in main?
  SDL_FreeSurface(temp);
Code:
if(gr->rcFlora[1].x >= 0 && gr->rcFlora[1].y >= 0 ) {
	printf("SDL_BlitSurface(gr->tower, NULL, screen, &gr->rcFlora[1]);\n"); //This prints
      	SDL_BlitSurface(gr->tower, NULL, screen, &gr->rcFlora[1]); //it crashes here
	printf("success!\n"); //This does not print.
I hope it makes sense. My question is why cant I access the address of an int in an array which is a member of a struct?
Reply With Quote
 

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with struct kdu Programming 9 31st March 2011 04:01 PM
BACKDOR in storage array by HP, in P2000/MSA2000 G3 model vermaden News 2 17th December 2010 06:14 AM
Need to access FakeRAID-0 Array on New System Weaseal FreeBSD General 2 17th January 2009 03:48 PM
gmirror array broken stukov FreeBSD General 5 15th July 2008 08:45 PM
RAID array not recognized on new Intel server clevershark OpenBSD Installation and Upgrading 6 14th May 2008 09:20 PM


All times are GMT. The time now is 05:12 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick