Thread: File i/o and ASCII question

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Looks like Line 18 is about the difference in the type of the function arguments in the caller and the callee as well as in the prototype. Pass one instead of two levels of indirection in the callee and the prototype ie
    Code:
    bool openFiles(FILE *pFPIn, FILE *pFPOut, int *input1, int *input2);
    IMHO though what's the need of passing all the arguments to openFiles() when you aren't even using them there. All the parameters can simply be local variables.

    Line 35 looks like part of an if-else statement. Its missing the if keyword and a parenthesis as in.
    Code:
    if (fscanf(fpIn, "%d%d", &input1, &input2) == 2)

  2. #2
    Registered User
    Join Date
    Oct 2008
    Posts
    33
    Quote Originally Posted by itCbitC View Post
    Looks like Line 18 is about the difference in the type of the function arguments in the caller and the callee as well as in the prototype. Pass one instead of two levels of indirection in the callee and the prototype ie
    Code:
    bool openFiles(FILE *pFPIn, FILE *pFPOut, int *input1, int *input2);
    IMHO though what's the need of passing all the arguments to openFiles() when you aren't even using them there. All the parameters can simply be local variables.
    Well I can take out the last two args, but the first two have to be there
    Code:
      bool openFiles(FILE **pFPIn, FILE **pFPOut);
    my teacher requires that I use that prototype


    Quote Originally Posted by itCbitC View Post
    Line 35 looks like part of an if-else statement. Its missing the if keyword and a parenthesis as in.
    Code:
    if (fscanf(fpIn, "%d%d", &input1, &input2) == 2)
    Thanks. Since it's not supposed to be an if-else statement I removed the end and it works properly now

    Code:
     fscanf(fpIn, "%d%d", &input1, &input2);

  3. #3
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    So it is required of you to use two levels of indirection where one suffices??

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by itCbitC View Post
    So it is required of you to use two levels of indirection where one suffices??
    If you want to change the value of the pointer passed in (say, by opening a file, which seems silly in a function called openFiles, but there you go) you would need to pass a pointer to the pointer.

  5. #5
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Quote Originally Posted by tabstop View Post
    If you want to change the value of the pointer passed in (say, by opening a file, which seems silly in a function called openFiles, but there you go) you would need to pass a pointer to the pointer.
    Your point is correct, however openFiles() isn't using or changing them in any way as it's using two local FILE * pointers.

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by itCbitC View Post
    Your point is correct, however openFiles() isn't using or changing them in any way as it's using two local FILE * pointers.
    Which is the problem.

  7. #7
    Registered User
    Join Date
    Oct 2008
    Posts
    33
    Quote Originally Posted by itCbitC View Post
    So it is required of you to use two levels of indirection where one suffices??
    Are you saying that one suffices in my function, or in general? If it's the former, than my function will need to be changed. (or my teacher made a typo) :|

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. File I/O both ASCII and binary handling in C++
    By random in forum C++ Programming
    Replies: 6
    Last Post: 08-16-2005, 04:53 AM
  3. Encrypting text file with ASCII hex
    By supaben34 in forum C++ Programming
    Replies: 1
    Last Post: 03-24-2005, 06:35 PM
  4. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 10:51 PM
  5. Binary File I/O
    By sean in forum C Programming
    Replies: 7
    Last Post: 08-20-2004, 10:56 AM