I'm having touble trying to send arrays from funciton to function. The thing I can't do is make a global variable (one of the rules set by the teacher). I don't know what I'm doing really, so let me know if it's even doable.
Mr.UNOwen 0 Junior Poster
Recommended Answers
Jump to Post>>so let me know if it's even doable
Absolutely and most definitely YES. We do it all the time. just pass the name of the array. Here is a simple example.
void foo(int array[]) { // blabla } int main() { int array[10]; foo(array); return 0; …
Jump to PostI'm having touble trying to send arrays from funciton to function. The thing I can't do is make a global variable (one of the rules set by the teacher). I don't know what I'm doing really, so let me know if it's even doable.
The answer is yes as specified …
Jump to Postarrays are always passed by reference, never by value. Both andor's example and mine pass the array by reference. The only difference between the two examples is in the function foo() -- In Andor's example the parameter is declared as a pointer and in mine it is not.
Jump to Postdepends on the operating system. The simplest way is to call system() function with the os-dependent command.
MS-Windows:
system("cls");
*nix
system("clear");
Others: I have no idea
Jump to Postyou can use precompile directives
#if defined(_WIN32) system("cls"); #else system("clear"); #endif
All 20 Replies
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
andor 25 Posting Whiz in Training
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Mr.UNOwen 0 Junior Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Mr.UNOwen 0 Junior Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
easy 0 Newbie Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
easy 0 Newbie Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
shariq 0 Newbie Poster
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
TylerSBreton 13 Junior Poster in Training
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
TylerSBreton 13 Junior Poster in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.