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

Discussion in 'C++' started by AMT2K5, Jun 27, 2005.

  1. AMT2K5

    AMT2K5 Guest

    "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
    }
     
    AMT2K5, Jun 27, 2005
    #1
    1. Advertising

  2. AMT2K5 wrote:
    > "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
     
    Victor Bazarov, Jun 27, 2005
    #2
    1. Advertising

  3. AMT2K5

    AMT2K5 Guest

    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.
     
    AMT2K5, Jun 27, 2005
    #3
  4. AMT2K5 wrote:
    > 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
     
    Victor Bazarov, Jun 27, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Roedy Green

    Little job for novice programmer

    Roedy Green, Sep 9, 2003, in forum: Java
    Replies:
    0
    Views:
    364
    Roedy Green
    Sep 9, 2003
  2. AMT2K5
    Replies:
    6
    Views:
    749
    Larry I Smith
    Jun 9, 2005
  3. AMT2K5
    Replies:
    9
    Views:
    6,523
    AMT2K5
    Jun 11, 2005
  4. AMT2K5
    Replies:
    6
    Views:
    878
    AMT2K5
    Jul 6, 2005
  5. AMT2K5
    Replies:
    12
    Views:
    655
    AMT2K5
    Jul 6, 2005
Loading...

Share This Page