Thank you Laserlight and Sebastiani!
"By the way, it looks like you are closing the file in the loop."
Yes you are right thanks for recalling me but on second thoughts if i wanna open a new file every time i think i would have to close the precedent.
I corrected the code. Now i just need to find out how to append a number each time to the filename.
For a reason 'strcpy' wont accept the first arg.
Code:
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main ()
{
FILE * pFile;
int i = 0;
char ch[5] = {0,1,2,3,4};
string filename = "file.txt", str2;
pFile = fopen (filename.c_str(),"w");
while (i<5)
{
cout << "Enter word: "; cin >> str2;
strcpy(filename.c_str(), ch[i]);
pFile = fopen (filename.c_str(),"w");
fprintf(pFile, str2.c_str());
fclose (pFile);
i++;
}
return 0;
}