What is the right syntax for function prototype involved with a two-dimensional array?
This is a discussion on Two-dimensional array within the C Programming forums, part of the General Programming Boards category; What is the right syntax for function prototype involved with a two-dimensional array?...
What is the right syntax for function prototype involved with a two-dimensional array?
now you can pass your 2d array to this function... also pass the size to be sure you're not accessing any un-owned memory.Code:void printArray(int array[][4]); /* declare function */
Or you can just pass the base address of the 2d array and number of rows and columns of that array.
And then implement the logic to get to particular element in the array in your function.
in one of my functions i create a 2 dimensional array getMessage[6][128] which is 6 lines of input going 128 characters across
i then ask for a number to use as an encryption key
then have to run this array through an encryption algorithm:
encryptedcode= (i- 32 +key)%95 +32)
then ask for the same number which will then decrypt the message.
basically, i'm going to have to access an array i create in another function from another function. Will i need pointers to do this?
Code:void encode(char getMessage[][]) { int i; for (i = 0; i < getMessage[][]; i++) { if (getMessage[i] != '\n') { getMessage[i] = (getMessage[i] - 32 +key)%95 +32); } else getMessage[i] = 0; } }