About
Community
Bad Ideas
Drugs
Ego
Erotica
Fringe
Society
Technology
register | bbs | search | rss | faq | about
meet up | add to del.icio.us | digg it
Go Back   Community > Technology > Technophiliacs & Technophiles
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Technophiliacs & Technophiles The Technophiliacs forum is for discussing any and all forms of tech and other types of social backwardness. Including discussions of strange home-brewed hardware technology. Where to get good tools. How to make fiberglass molds. Computer hardware and software technolgy, including operating systems, applications, networking, hardware, CPU's, disk drives, and other geeky things. Viruses and Artificial Life discussions. How to write HTML. End user tools discussions and support issues. Gating the Internet with other nets. If your computer is better than anyone else's computer, you are required to post a message explaining why. You'll probably be wrong, especially if you're a Mac or BeOS user, but post anyway.

Reply
 
Thread Tools Display Modes
  #1   Add KING G to your ignore list  
Old 2007-04-17, 07:12
KING G KING G is online now
Regular
 
Alberta - Calgary - Canada Send a message via MSN to KING G Send a message via Yahoo to KING G KING G is an unknown
Default A C++ question

when you are trying to pass a variable as an argument to a function, you use this code:

Code:
PutItHere = Function(NameOfArgument);
now what would you need to transfer arrays through functions?

Last edited by KING G : 2007-04-17 at 07:25.
Reply With Quote
  #2   Add ArgonPlasma2000 to your ignore list  
Old 2007-04-17, 07:30
ArgonPlasma2000 ArgonPlasma2000 is offline
Moderator
 
Self-proclaimed Totse Pope ArgonPlasma2000 is worth listening to ArgonPlasma2000 is worth listening to ArgonPlasma2000 is worth listening to ArgonPlasma2000 is worth listening to
Post Re: A C++ question

A pointer.

Code:
void sortThisArray(int*);



int main(){

   int someArray[5];

    sortThisArray(someArray);

    return 0;

}
__________________
In the correct dosage, violence solves anything.
Reply With Quote
  #3   Add Axiom to your ignore list  
Old 2007-04-17, 07:46
Axiom Axiom is offline
Regular
 
Australia Axiom is an unknown
Default Re: A C++ question

You have a couple options.

If you're wanting to return a value you can create a struct object and pass that to the function...

Code:
#include <cstdlib>
#include <iostream>

using namespace std;

struct mystruct {
    int array_name[5];
};

mystruct Function(mystruct var1);

int main(int argc, char *argv[])
{
    //Create the struct to house the array
    mystruct varable1;
    //Print out array
    cout << "Array Before Passing To Function" << endl;
    cout << varable1.array_name[0] << endl;
    cout << varable1.array_name[1] << endl;
    cout << varable1.array_name[2] << endl;
    cout << varable1.array_name[3] << endl;
    cout << varable1.array_name[4] << endl;
    //Pass struct to function
    varable1 = Function(varable1);
    //Print array again
    cout << "Array After Passing To Function" << endl;
    cout << varable1.array_name[0] << endl;
    cout << varable1.array_name[1] << endl;
    cout << varable1.array_name[2] << endl;
    cout << varable1.array_name[3] << endl;
    cout << varable1.array_name[4] << endl;
    //wxDevcpp Code
    system("PAUSE");
    return EXIT_SUCCESS;
}

mystruct Function(mystruct var1){
   //Fill array with 1-5
   var1.array_name[0] = 1;
   var1.array_name[1] = 2;
   var1.array_name[2] = 3;
   var1.array_name[3] = 4;
   var1.array_name[4] = 5;
   return var1;
}
Note: I can't spell variable
Reply With Quote
  #4   Add KING G to your ignore list  
Old 2007-04-17, 07:48
KING G KING G is online now
Regular
 
Alberta - Calgary - Canada Send a message via MSN to KING G Send a message via Yahoo to KING G KING G is an unknown
Default Re: A C++ question

ummm, I'm gonna go with teh pointer
Reply With Quote
  #5   Add Axiom to your ignore list  
Old 2007-04-17, 07:58
Axiom Axiom is offline
Regular
 
Australia Axiom is an unknown
Default Re: A C++ question

lol, np... This is it in theory

Code:
struct mystruct {
    int array_name[5];
};

mystruct Function(mystruct var1);

int main()
{
    mystruct varable1;
    variable1 = Function(variable1);
    return 0;
}

Last edited by Axiom : 2007-04-18 at 06:05.
Reply With Quote
  #6   Add ArgonPlasma2000 to your ignore list  
Old 2007-04-17, 08:01
ArgonPlasma2000 ArgonPlasma2000 is offline
Moderator
 
Self-proclaimed Totse Pope ArgonPlasma2000 is worth listening to ArgonPlasma2000 is worth listening to ArgonPlasma2000 is worth listening to ArgonPlasma2000 is worth listening to
Talking Re: A C++ question

Lemme guess, they skipped over for loops, Axiom?
__________________
In the correct dosage, violence solves anything.
Reply With Quote
  #7   Add Axiom to your ignore list  
Old 2007-04-17, 08:10
Axiom Axiom is offline
Regular
 
Australia Axiom is an unknown
Default Re: A C++ question

Loops?... They have loops now?...

Reply With Quote
  #8   Add lifejunkie to your ignore list  
Old 2007-04-17, 14:45
lifejunkie lifejunkie is offline
Moderator
 
A dream within a dream. Send a message via ICQ to lifejunkie lifejunkie is worth listening to lifejunkie is worth listening to lifejunkie is worth listening to lifejunkie is worth listening to
Default Re: A C++ question

Quote:
Originally Posted by Axiom View Post
lol, np... This is it in theory

Code:
struct mystruct {
    int array_name[5];
};

mystruct Function(mystruct var1);

int main()
{
    mystruct varable1;
    varable1 = Function(varable1);
    return 0;
}
Why would you do that?


Code:
/* Create the dataset */
void makedata(int *data, int size)
{
  for (int i = 0; i < size; i++)
    data[i] = i * 2 + 1;
}

/* Display the dataset */
void showdata(int *data, int size)
{
  for (int i = 0; i < size; i++)
    printf("%d\n", data[i]);
}

/* Driver */
int main( void )
{
  const int data_size = 5;

  int data[data_size];

  makedata(data, data_size);
  showdata(data, data_size);

  return(0);
}
Reply With Quote
  #9   Add Axiom to your ignore list  
Old 2007-04-17, 15:15
Axiom Axiom is offline
Regular
 
Australia Axiom is an unknown
Default Re: A C++ question

Quote:
Originally Posted by lifejunkie View Post
Why would you do that?
Good question...

I felt the syntax used by the OP disqualified void functions...
Reply With Quote
  #10   Add KING G to your ignore list  
Old 2007-04-17, 23:12
KING G KING G is online now
Regular
 
Alberta - Calgary - Canada Send a message via MSN to KING G Send a message via Yahoo to KING G KING G is an unknown
Default Re: A C++ question

I'm gonna try all these methods out.

I belive there is a way to do this using loops? I mean, to send an entire word or so to a function using one varible that (for) loop.

I'm not into solving the problem now, I want to learn more.

does anyone think that I should start learning a library, if so, which one?

thanks alot guys, you've been a great help.
Reply With Quote
This thread continued for 3 pages in the real archive, 23 posts total - only page 1 survived here.
Reply


Thread Tools
Show Printable Version Show Printable Version
Email this Page Email this Page
Display Modes
Linear Mode Linear Mode
Hybrid Mode Switch to Hybrid Mode
Threaded Mode Switch to Threaded Mode

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

 
To the best of our knowledge, the text on this page may be freely reproduced and distributed.
 

totse.com certificate signatures
 
 
About | Community | Bad Ideas | Drugs | Ego | Erotica | Fringe | Society | Technology
Hot Topics