fwrite error: bad address

This is a discussion on fwrite error: bad address within the C Programming forums, part of the General Programming Boards category; Hi everybody! I'm having a silly though extremely annoying problem when using fwrite. What I'm trying to do is to ...

fwrite error: bad address

Hi everybody! I'm having a silly though extremely annoying problem when using fwrite. What I'm trying to do is to calculate a random size for the message I'm about to write (although this size is limited by SIZEMAX), create a temporary file to storage it (my message) and finally write the message in it. This message consists of a series of identical characters, whose nature will depend on the value of 'i'. Now, the thing is I usually get an error (sometimes, funnily enough, it works (or so it seems)) in fwrite: "Bad address". Why is this? How can I fix it? Any idea?

Here's my code, BTW (the comments are in Spanish, but they tell the same I just explained):

But the reason I create a temporary file to storage the message is that it's too big to storage it in a variable (you can storage it in a variable, of course, but it will waste a lot of memory), so I'm afraid that isn't an option for me.

And about...

In the worst case you write SIZEMAX-1 char's starting from letra[0]. -> segfault.