Accessing Void Function Question

This is a discussion on Accessing Void Function Question within the C++ Programming forums, part of the General Programming Boards category; I'm working on a project for school, and have a question. For the sake of clarity, let's say I have ...

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    20

    Accessing Void Function Question

    I'm working on a project for school, and have a question. For the sake of clarity, let's say I have two functions:

    1. int main() //reads a word from file
    2. void ReadFile() //stores contents of a file in an array

    In main(), I have to see if the word I pulled from the file exists in the array in ReadFile(). My problem, is I don't know how to access the array in ReadFile() from main() since ReadFile() is of type void (a requirement) and since I can't use reference parameters or pointers.

    Please let me know if you have any ideas on how to access this data.

    Thanks,
    Kevin
    Last edited by liquidspaces; 03-27-2003 at 10:51 AM.

  2. #2
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    I don't see why you'd want to store the contents into a local array of a void function.

    If you're stuck with using a local variable for the array then you can use a global variable that is populated based on a test performed in the void function. If you aren't stuck with having to use a local variable for the array then declare the array globally.

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    20
    Unfortunately, those options are out of the question. I definitely don't want to do it this way, but for this assignment my professor created the function prototypes and I have to figure out how to make it work within the constraints of those prototypes and the specs.

    I did, however, figure out how to make this work the way it's supposed to...it seems that simply calling the function from main allows me to manipulate the data. I wasn't aware that it would have such an effect.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Replies: 3
    Last Post: 05-13-2007, 08:55 AM
  3. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  4. Replies: 5
    Last Post: 02-08-2003, 06:42 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21