I managed to fix your code, but I basically had to switch over to
std::strings since they're so much easier for me to work with.
(Not that you
have to use them, but....)
Anyways, I can't even keep track of what I changed, so I'll just point out some of the bigger issues:
-- You're trying to create
n different files. That means you need
n different (random) file names. Currently, you're only generating one (
ah). By the way, that string isn't null-terminated -- you should probably fix that (a simple
ah[20] = '\0'
should do).
So, instead of generating a (single) random filename now, generate them as you go, when you need them. (More on that later.)
By the way, also see my other post above about the
srand issue.
-- I would open your files (all of them) in binary mode (with
ios::binary). (Fixed a minor issue with weird splits for me)
--
while(!fc.eof())
Don't loop on
eof. You're trying to create
n files, so make this a
for
loop that creates
n files:
for (int i = 0; i < n; ++i)
At the beginning of this
for
loop would be a good place to generate a new random file name.
By the way, at least on my OS, the '*' (asterisk) character isn't a valid character in a file name, so you should probably remove that from your
alphanum string (speaking of which, you can get the size of it by calling
strlen -- don't rely on
sizeof
).
-- Instead of
1 2
|
fc>>letter;
fcs<<letter;
|
Do this:
1 2
|
fc.get(letter);
fcs.put(letter);
|
.
That's because
fc >> letter
will eat the whitespace, and you probably don't want that.
Same thing down below when you write to your "extra" file.
--
1 2
|
tell=fc.tellg();
fc.seekg(tell);
|
Not sure what this is for, but you don't need it.
-- By the way: you should probably check to make sure that you actually have a file open.