Is this possible to do in C++ {Novice Programmer}

A

AMT2K5

"FILE* setFp(char []) - setFp is passed a null terminated character
array that contains the name of a file. Before attempting to open the
file check the state of fp. If fp is not null close fp. Open the file
in read mode using fp. Return fp."

In my assignment it wants the setFP function to take in a nameless
parameter? I am used to seeing something like "char a[]", not just an
empty variable name. How do I act on the incoming string if it has no
name?

class Bank
{
FILE* fp;
}

FILE* Bank::setFP(char [])
{
//some code goes here
}
 
V

Victor Bazarov

AMT2K5 said:
"FILE* setFp(char []) - setFp is passed a null terminated character
array that contains the name of a file. Before attempting to open the
file check the state of fp. If fp is not null close fp. Open the file
in read mode using fp. Return fp."

In my assignment it wants the setFP function to take in a nameless
parameter? I am used to seeing something like "char a[]", not just an
empty variable name. How do I act on the incoming string if it has no
name?

I think you're looking too much into the details of the assignment.

Function declarations do not need argument names, only the types. So,
whoever wrote that assignment decided to omit the name for your own
benefit: so you could name it as you wish. If you think you need to
use that argument, you will have to call it something. If you want it
to be 'a', use 'a'. If you want your code to be self-documenting, do
not use single-letter variable names.
class Bank
{
FILE* fp;
}

FILE* Bank::setFP(char [])
{
//some code goes here
}

V
 
A

AMT2K5

Ok, thanks for the tip.

Can I now do, fp = fopen(a, "r"); ?

I think I forgot how to set the pointer to the incoming string.
 
V

Victor Bazarov

AMT2K5 said:
Ok, thanks for the tip.

Can I now do, fp = fopen(a, "r"); ?

Should be alright. Are you getting a compile error?
I think I forgot how to set the pointer to the incoming string.

I am not sure I understand this comment.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top