|
|
 |
 |
 |
 |
register |
bbs |
search |
rss |
faq |
about
|
 |
 |
meet up |
add to del.icio.us |
digg it
|
 |
 |
| 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. |
 |
|
# 1

2007-04-17, 07:12
|
|
|
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.
|
# 2

2007-04-17, 07:30
|
|
|
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.
|
# 3

2007-04-17, 07:46
|
|
Regular
|
|
Australia
|
|
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
|
# 4

2007-04-17, 07:48
|
|
|
Re: A C++ question
ummm, I'm gonna go with teh pointer 
|
# 5

2007-04-17, 07:58
|
|
Regular
|
|
Australia
|
|
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.
|
# 6

2007-04-17, 08:01
|
|
|
Re: A C++ question
Lemme guess, they skipped over for loops, Axiom?
__________________
In the correct dosage, violence solves anything.
|
# 7

2007-04-17, 08:10
|
|
Regular
|
|
Australia
|
|
Re: A C++ question
Loops?... They have loops now?...

|
# 8

2007-04-17, 14:45
|
|
|
Re: A C++ question
Quote:
Originally Posted by Axiom
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);
}
|
# 9

2007-04-17, 15:15
|
|
Regular
|
|
Australia
|
|
Re: A C++ question
Quote:
Originally Posted by lifejunkie
Why would you do that?
|
Good question...
I felt the syntax used by the OP disqualified void functions...
|
# 10

2007-04-17, 23:12
|
|
|
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.
|
This thread continued for 3 pages in the real archive, 23 posts total - only page 1 survived here.
| Thread Tools |
 Show Printable Version
 Email this Page
|
| Display Modes |
Linear Mode
 Switch to Hybrid 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
HTML code is Off
|
|
|
|
 |
 |
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
|
 |
 |
 |
 |
|
|