monitor file access
+ Reply to Thread
Results 1 to 8 of 8

Thread: Problem In C++

  1. #1
    Join Date
    Jan 2007
    Posts
    11

    Problem In C++

    Hello Everybody... I'm a student and i have recently started learning C++.
    We are learning functions right now.. somebody please tell me how to use arrays given in the main function in some other user defined function...

    like in the prog:
    void main()
    {
    void array();
    int n[*0]={*,2,*,4,5,6,7,8,*,*0}
    getch();
    array()
    }

    void array()
    {
    int var[*0];
    cout<<var;
    }

    u see i want to use the value given in the main function i.e. value stored in array n in my function 'array'... how can i do that.. plz tell... if an example can be given i'll be thankful

  2. #2
    Join Date
    Sep 2006
    Posts
    1,649
    You'd have to modify your function to get user input for the array values, instead of using ones entered in the main function.
    "Workers of the world unite; you have nothing to lose but your chains." -Karl Marx

  3. #3
    Join Date
    Jan 2007
    Posts
    11
    Quote Originally Posted by Moonbat
    You'd have to modify your function to get user input for the array values, instead of using ones entered in the main function.
    Can u plz explain????

  4. #4
    Join Date
    Jan 2007
    Posts
    9

    lol

    lol , im the Beast from the EAst in the C ++
    so u said u want array ... um.. i dont know whats array suppose 2 mean we never learn that . but i do know - that we use - getchar.. then we user putchar --> its like printf(" bla bla bla \n")
    if u want more explane for putchar just ask

  5. #5
    Join Date
    Sep 2005
    Posts
    2,050
    Quote Originally Posted by Vipul Motiwala
    Hello Everybody... I'm a student and i have recently started learning C++.
    We are learning functions right now.. somebody please tell me how to use arrays given in the main function in some other user defined function...

    like in the prog:
    void main()
    {
    void array();
    int n[*0]={*,2,*,4,5,6,7,8,*,*0}
    getch();
    array()
    }

    void array()
    {
    int var[*0];
    cout<<var;
    }

    u see i want to use the value given in the main function i.e. value stored in array n in my function 'array'... how can i do that.. plz tell... if an example can be given i'll be thankful
    There are many ways, but here are a few:

    Code:
    void array(int var[*0]);
    
    int main()
    {
         int n[*0] = {*,2,*,4,5,6,7,8,*,*0}
         getch();
         array(n)
    }
    
    void array(int var[*0]);
    {
    cout << var;
    }
    Code:
    void array();
    int n[*0] = {*,2,*,4,5,6,7,8,*,*0}
    
    int main()
    {
         int n[*0] = {*,2,*,4,5,6,7,8,*,*0}
         getch();
         array(n)
    }
    
    void array();
    {
    cout << n;
    }
    There's probably mistakes in there, but you get the idea. You can pass the array in through the function parameters, or you can declare the data globally.

    One problem with your code was that you declared the array function inside main(), but it should be declared before any of that. I fixed it in both those pieces of code.

  6. #6
    Join Date
    Jan 2007
    Posts
    11
    Quote Originally Posted by mike*0*
    There's probably mistakes in there, but you get the idea. You can pass the array in through the function parameters, or you can declare the data globally.
    thanx mike... but can u explain a little more about declaring variables gloabally.

  7. #7
    Join Date
    Sep 2005
    Posts
    2,050
    Quote Originally Posted by Vipul Motiwala
    thanx mike... but can u explain a little more about declaring variables gloabally.
    All C++ tutorials explain global variables -- try searching google for one.

  8. #8
    Join Date
    Jan 2007
    Posts
    11
    Quote Originally Posted by mike*0*
    All C++ tutorials explain global variables -- try searching google for one.
    OK mike...Thank you for your guidance

+ Reply to Thread

Similar Threads

  1. problem
    By minaaaa in forum General discussion
    Replies: 3
    Last Post: 05-11-2013, 06:37 AM
  2. I got a problem
    By Gabriel in forum Security & Encryption
    Replies: 2
    Last Post: 09-01-2006, 06:41 PM
  3. Problem...
    By liquinn in forum Internet Privacy
    Replies: 2
    Last Post: 08-04-2006, 01:28 PM
  4. another msn problem
    By Unregistered in forum Viruses and Trojans
    Replies: 4
    Last Post: 06-11-2004, 10:19 AM
  5. DNS problem
    By Unregistered in forum Internet Privacy
    Replies: 0
    Last Post: 10-28-2002, 02:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts