Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

A.Avinash_Goutham

can any1 help me regarding "passing multidimensional arrays"?

  • one year ago
  • one year ago

  • This Question is Closed
  1. A.Avinash_Goutham
    Best Response
    You've already chosen the best response.
    Medals 0

    i have a dynamic array and i have to fill it with random values............. so i have to do smthin like randomAssign(&array,size) void randomAssign(int ***array,int size) { int i,j; for(i=1...size) for(j=1...size) array[i][j]=rand(); return; } but this gives a segmentation fault? so wer did i go wrong?

    • one year ago
  2. A.Avinash_Goutham
    Best Response
    You've already chosen the best response.
    Medals 0

    @nick67 @slotema

    • one year ago
  3. A.Avinash_Goutham
    Best Response
    You've already chosen the best response.
    Medals 0

    array is of type int ** int **array; array = builder(size); and my builder function is here int ** builder(int n) { int i; int *array=malloc(n*sizeof(int)); for(i=0;i<n;i++) array[i]=(int *)malloc(n*sizeof(int)); return array; } language s c

    • one year ago
  4. A.Avinash_Goutham
    Best Response
    You've already chosen the best response.
    Medals 0

    @ktobah

    • one year ago
  5. ktobah
    Best Response
    You've already chosen the best response.
    Medals 0

    You know when you want to pass an Array as argument, don't use &, because C/C++ consider arrays as addresses. Try this .

    • one year ago
  6. A.Avinash_Goutham
    Best Response
    You've already chosen the best response.
    Medals 0

    nope tried that.............it dint work

    • one year ago
  7. A.Avinash_Goutham
    Best Response
    You've already chosen the best response.
    Medals 0

    any ideas?

    • one year ago
  8. ktobah
    Best Response
    You've already chosen the best response.
    Medals 0

    I really don't have any idea, sorry.

    • one year ago
  9. A.Avinash_Goutham
    Best Response
    You've already chosen the best response.
    Medals 0

    tsk thanks nyway.......

    • one year ago
  10. ktobah
    Best Response
    You've already chosen the best response.
    Medals 0

    You're welcome.

    • one year ago
  11. nick67
    Best Response
    You've already chosen the best response.
    Medals 0

    @A.Avinash_Goutham try something like this (with this example you have a 10x10 array with random values up to 99: #include <iostream> #include <ctime> #include <cstdlib> using namespace std; #define ARRAY_SIZE 10 void randomAssign(int *array_ptr,int size) { int i,j; srand ( time(NULL) ); for(i=0;i<size;i++) for(j=0;j<size;j++) { *array_ptr = rand() % 100; array_ptr++; } return; } int main() { int array[ARRAY_SIZE][ARRAY_SIZE]; randomAssign(&array[0][0], ARRAY_SIZE); return 0; }

    • one year ago
  12. A.Avinash_Goutham
    Best Response
    You've already chosen the best response.
    Medals 0

    Sir, the array should be dynamic...........i shud be able to give the size at the run time.....

    • one year ago
  13. A.Avinash_Goutham
    Best Response
    You've already chosen the best response.
    Medals 0

    main() { int n,i,j; printf("enter the size of the maze:"); scanf("%d",&n); static int **array; array=builder(n); if(array) { printf("array creation succesfull\n"); } printf("%d\n",rand()); assign(array,n); randomAssign(array,n); print(array,n); } int ** builder(int n) { int i; int *array=malloc(n*sizeof(int)); for(i=0;i<n;i++) array[i]=(int *)malloc(n*sizeof(int)); return array; } void print(int **array,int n) { int i,j; for(i=0;i<n;i++) { for(j=0;j<n;j++) printf("%d ",array[i,j]); printf("\n"); } return; } void assign(int **array,int n) { int i,j; for(i=0;i<n;i++) for(j=0;j<n;j++) { printf("enter element array[%d][%d]:",i,j); scanf("%d",&array[i][j]); } return; } void randomAssign(int **array,int n) { int i,j; for(i=0;i<n;i++) for(j=0;j<n;j++) array[i][j]=rand()%2; return; }

    • one year ago
  14. A.Avinash_Goutham
    Best Response
    You've already chosen the best response.
    Medals 0

    that was my code..

    • one year ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.