K
Karl Heinz Buchegger
sachin said:strcpy(filename[1],filename[0]);
strcat(filename[1],&ext);
ext is a single character.
A single character is not a string!
Because a C-style string always has to be terminated by a '\0' character!
char Extension[2];
Extension[0] = ext;
Extension[1] = '\0';
strcat( filename[1], Extension );
Also: it's actually a good idea to output that filename during
the development process.
outfile.open(filename[1],ios::binary);//this line was the culprit..
It's also a good idea, to check, if the open succeeded.
}
outfile.close();
infile.close();
}
As a rule of thumb:
File classes have some way to check if operations like open have
succeeded. It is an extremely good idea to use them! There is
no point in writing to a file stream which has not opened correctly,
ignoring the error checking facilities and yelling for help aftwards.
If the open failed, it is also a good idea to indicate which
file (filename) could not be opened or created. During the
development process it is also a good idea to output status
messages (eg: now opening file 'filename' - succeeded) which
can be removed once the program is finished.
It is also a good idea, if you program in C++, to use the C++
string class.