You don't need to treat fn as an array except at its declaration. Declare it as a char* in your function parameters, and just pass around fn, nothing more.
Hey, there. For starters, always make sure that your function prototype and the function definition have the same data type in their parameters (i.e. both are char*-types.) You had the right idea in the prototype, but in the function definition things got a little scrambled.
For starters, when you make the ofstream "myFile", the syntax should be:
ofstream myFile;
not
ofstream.myFile;
Also, remember that the myFile.open() function takes a pointer to the string as a parameter. It looks like you were trying to pass the function the whole array, but that's overkill and it's improper syntax. Since your c-string is named "fn", the pointer to the c-string is simply "fn", so your myfilemaker() function should read:
Also, just to get in the habit of good programmin', try to make your main() function return a value of 0, that's what generally symbolizes a successful execution. If you want to save some system resources, as will, use cin.get() instead of pausing the system, it's substantially less memory-intensive and performs the same function.
I don't want to reiterate what was already said. Keep in mind that C-like strings, i.e. char*, are only a sequence of characters that ends with a null-termination character, or 0 (or '\0'). Though they are actually arrays or characters, they are called null-terminated strings. To work with such strings, you pass the address of the first character in the array. A function that takes a null-terminated string as input, actually takes a pointer to char*, because that is the type for the address of the first character in the array.
Note that since myfile is about to go out of scope anyway, the .close() call is redundant and unnecessary. The file will be closed when the ofstream's destructor is called.
Bookmarks