•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 422,412 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 5,046 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 503 | Replies: 8 | Solved
•
•
Join Date: Nov 2006
Location: Athens, Greece
Posts: 198
Reputation:
Rep Power: 2
Solved Threads: 9
hi guys, it's been a while since i used c for anything so here goes a question tha may seem silly.
I have 2 variable length arrays....
...What i want to do is find a way to swap the pointers to the arrays. So that i can get rid of the last loop.
I figured that since i only need to calculate "after" based on "before" and then make "after"->"before" and recalculate "after".
It would save a lot of time if i just swapped the 2 pointers.
i tried the following but with no luck:
thanks in advance
-nicolas
I have 2 variable length arrays....
c Syntax (Toggle Plain Text)
int main() { int n = 5; int m = 6; int before[n][m]; int after[n][m]; array_function( 5, 6, before, after ); } void array_function(int rows, int cols, float after[rows][cols] , float before[rows][cols]) { //for some iterations for(;;) { //for all the elements int the array for (i=1; i<rows; i++) for(j=1; j<cols; j++) after[i][j] = 4 * before[i][j] //afterwards prepare for the next iteration [1] for (i=1; i<rows; i++) for(j=1; j<cols; j++) before[i][j]=after[i][j]; } }
...What i want to do is find a way to swap the pointers to the arrays. So that i can get rid of the last loop.
I figured that since i only need to calculate "after" based on "before" and then make "after"->"before" and recalculate "after".
It would save a lot of time if i just swapped the 2 pointers.
i tried the following but with no luck:
c Syntax (Toggle Plain Text)
//define function like this: void array_function(int rows, int cols, float &after[rows][cols] , float &before[rows][cols]) //call it like this: array_function( 5, 6, &before, &after );
thanks in advance
-nicolas
Two roads diverged in a wood, and I— I took the one less traveled by, and that has made all the difference.
by Robert Frost the "The Road Not Taken"
by Robert Frost the "The Road Not Taken"
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Help needed filling array with unique random numbers (C++)
- Index array & sort algorithm??? (Java)
- Search program help in modifications (Java)
- Arrays in c/c++ language (C++)
- Need Help Revising Array program: Visual C++ (C++)
- bubble sorting in an array (C)
- Help on assignment (C)
- Need help calculating Median when array is even (C++)
- How can i swap two buttons by clicking on them (Java)
Other Threads in the C Forum
- Previous Thread: program just hangs
- Next Thread: How do i use EOF in my program ??



Threaded Mode