Save_bitmap loop
Eradicor

Ok. Dont ask why i need following, program code. Just suffice to say, i need it:

I need something like this ->

while(x = 1000) {
draw_certain_bitmap_full_of_stuff();
save_bitmap(certain_bitmap,"certain(int x).bmp");
}

Now it should do 1000 bmp files containing certain_bitmap and the file names should be:

certain1.bmp
certain2.bmp
certain3.bmp
certain4.bmp
etc
...

And for curious, no this is not for making screen capturing, but is ment for very special kind of animation program for our next film project. :D

FAST ANSWERS PLEASE.. And correct too!

Mokkan

Like this?

int x = 1;
while(x <= 1000){
    char filename[64];
    sprintf(filename, "certain%d.bmp", x);
    draw_certain_bitmap_full_of_stuff();
    save_bitmap(certain_bitmap, filename);
    x++;
}

EDIT: Fixed code.

Onewing
Quote:

FAST ANSWERS PLEASE.. And correct too!

Sure! As soon as I find the question...

CGamesPlay

Don't forget to increment x :)

[append]
IRC beats CGamesPlay to the edit.

Jonatan Hedborg

First i considered not answering, because of your well, arrogant, tone.

But what the hey, i feel like "giving".

And you obviously dont have any idea what you are doing.

for(int i=1; i<=1000; i++)
{
  draw_certain_bitmap_full_of_stuff(certain_bitmap);
  char tmp[256];
  sprintf(tmp,"certain%i.bmp",i);
  save_bitmap(certain_bitmap,tmp);
}

Untested, naturally, so i can't give any guarantees, but that should do it.

ReyBrujo

I would use %04d instead, to get 0001, 0002, 0003, etc. But it is just my taste.

A J

i would be more concerned with people still using sprintf hasn't the last 3 years of "secure" programming hyperbole from just about everyone meant anything?

and whats with using file[64] and file[256] ? how about using MAX_PATH

and what about clearing it before using it ?

Jonatan Hedborg

I heard it mentioned that sprintf is "bad" in some way. Please elaborate =)
You don't need to clear it afaik, as it overwrites anything in the buffer and terminates with a \0. And i agree that %04i or even %05i would be better than just plain %i.

Evert
Quote:

I heard it mentioned that sprintf is "bad" in some way. Please elaborate =)

Buffer overruns. It doesn't check if it writes outside the size of the allocated memory buffer (because you don't tell it the size of the memory buffer).

Quote:

You don't need to clear it afaik

Correct.

Jonatan Hedborg

Right. That would be bad. But it's not an issue here anyway.

A J

Bad code is always an issue.
This is computer science not poetry.
Computer science i tell you computer science.. mwahwhaaa!!

Eradicor
Jonatan Hedborg said:

First i considered not answering, because of your well, arrogant, tone.

Heh thats new.

Well when you are on a hurry you dont have luxuary of being polite.

Anyway i solved this problem another way. Thanks however. That filename routine comes handy else where tho.

Thread #584944. Printed from Allegro.cc