ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Well, i'm trying to do a game in C using SDL libs. I had done some things but today, while adding some things to the player file, i discovered something really weird:
Code:
//loads the playah!!
struct player load_playa(char fplaya[MAX_CHAR])
{
struct player temp;
FILE *tfile;
char fname[MAX_CHAR];
int i,j,nframes,time;
int tint;
//loads the player info file
tfile = fopen(fplaya,"r");
//speed is:
fscanf(tfile,"speed=%i\n",&tint);
temp.speed = (Uint8)tint;
fscanf(tfile,"jump=%i\n",&tint);
temp.maxJump = (Uint8)tint;
printf("speed: %i max_jump: %i\n",temp.speed,temp.maxJump);
//until the four sprites are loaded, it does:
for (j = 0; j <= IDS; j++)
{
//checks the number of frames...
fscanf(tfile,"frames=%i\n",&nframes);
for (i=0;i<nframes;i++)
{
//and loads the pic, time and mask of each frame...
fscanf(tfile,"pic=%s\n",&fname);
temp.images[j][i].pic[0] = LoadImg(fname);
//Generates the surface of the picture looking tio the inverse side.
temp.images[j][i].pic[1] = ReversePic(temp.images[j][i].pic[0]);
//sets the transparecy:
SetTrans(temp.images[j][i].pic[0],0,0);
SetTrans(temp.images[j][i].pic[1],0,0);
//timing...
fscanf(tfile,"time=%i\n",&time);
temp.images[j][i].time = time;
//masks...
fscanf(tfile,"mask=%s\n",&fname);
temp.images[j][i].rmask = LoadImg(fname);
temp.images[j][i].lmask = ReversePic(temp.images[j][i].rmask);
}
temp.maxFrames[j] = nframes;
}
printf("speed: %i max_jump: %i\n",temp.speed,temp.maxJump);
return temp;
}
dont have time to find exact problem but somewhere in your loops, your writing to your array out of bounds and you hapen to be overwriting speed and maxJump and most likely other variables to. go through it with gdb or in your head and you'll find your going out of bounds somewhere.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.