Sponsored Content
Top Forums Programming Making an array of 2D arrays in C Post 303021771 by Corona688 on Thursday 16th of August 2018 12:46:45 PM
Old 08-16-2018
int * isn't enough information for C to know what kind of array is being pointed to. That assumes a single integer or 1D array.

int *matrix[size][size] does not make pointers to 2d arrays -- it makes a 2d array of pointers.

Pointing to an array of known size takes this slightly wonky syntax:

int (*variablename[size][size]) [elements];

The stuff inside the red brackets defines the array being pointed to, the [elements] outside it defines the actual number of elements.

An example:

Code:
int main(void)
{
        int arr2d[2][2]={ {1,2},{3,4} };
        int arr2db[2][2]={ {5,6},{7,8} };

        int (*ptr[2][2])[2]= { arr2d, arr2db };
}

I thank @yifangt for pointing out to me this was even possible. C has a few weird corners.

Last edited by Corona688; 08-16-2018 at 05:16 PM..
These 2 Users Gave Thanks to Corona688 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

split and making an array inside another array

I want to run an awk split on a value that has been pushed through an array and I was wondering what the syntax should be?? e.g. running time strings through an array and trying to examine just minutes: 12:25:30 10:15:13 08:55:23 awk ' NR==FNR{ ... (2 Replies)
Discussion started by: dcfargo
2 Replies

2. Shell Programming and Scripting

Perl array of arrays

Hi, I am trying to assign an array as a value to one of the array element, I mean I have an array @KS and array @kr. I want array @KS to hold @kr as an element. So I am doin this $KS=@kr; But the value stored is number of elements in the @kr array. Can... (2 Replies)
Discussion started by: eamani_sun
2 Replies

3. Shell Programming and Scripting

Searching array of arrays in perl

Suppose there are two arrays of arrays: @A = ( , , , ); @B = ( , , , , ); For each of $A, $A, $A..., I want to find the corresponding one in @B (match the letter, like $A eq $B), and print out both the second item, for example, $A and $B. How can I do this in perl? grep + map? Hope I... (1 Reply)
Discussion started by: zx1106
1 Replies

4. Shell Programming and Scripting

Making array of string with bash

in.txt libgstreamer gstreamer-0_10 gstreamer-0_10-plugins-good gstreamer-0_10-plugins-base Output should be: libgstreamer gstreamer-0_10 gstreamer-0_10-plugins-good gstreamer0_10-plugins-base Then: #!/bin/sh v=(libgstreamer gstreamer-0_10 gstreamer-0_10-plugins-good... (5 Replies)
Discussion started by: cola
5 Replies

5. Programming

Perl arrays and loop through array

Hi All I need to get <STDIN> from a user. the <STDIN> is a range of number delimited by "," (comma) and can be with range delimited by "-". Example: 1,2,3,4-9,12,15,34-36,70 Now I need to get this from the user and go on each number and "Do something"... but when trying to do this as above... (2 Replies)
Discussion started by: RedGrinGo
2 Replies

6. Shell Programming and Scripting

using arrays and also help with array.contains functionality

here is what i have... i=1 while read line do if grep -i-q "create procedure"<<<$line then startline="$line" endline="blahblah" Get procedure name into a variable named procName procName="procedure name is stored" do some... (2 Replies)
Discussion started by: vivek d r
2 Replies

7. Shell Programming and Scripting

perl script :making array

Hi , i have a perl script which takes 'csv; file as input parameter and performs some tasks. CSV file format : MAGENTF,AGENTF8,mahfr001,tksfr01,. ./.profile 1>/dev/null 2>&1;ps -fe|grep 'gn1avm_agent -n AGENTF8'|grep gn1avm_agent|tr -s '' ''|cut -d ' ' -f 3|xargs kill -9,,. ./.profile... (3 Replies)
Discussion started by: deepakiniimt
3 Replies

8. Shell Programming and Scripting

Bash arrays: rebin/interpolate smaller array to large array

hello, i need a bit of help on how to do this effectively in bash without a lot of extra looping or massive switch/case i have a long array of M elements and a short array of N elements, so M > N always. M is not a multiple of N. for case 1, I want to stretch N to fit M arrayHuge H = (... (2 Replies)
Discussion started by: f77hack
2 Replies

9. Programming

Calling an array of arrays in C.

Corona688 was great in helping me learn how to create arrays that hold other two dimensional array here. Unfortunately I didn't think ask about how to implement or call them. Basically, I'm trying to call an array of two-dimensional arrays like this: declaration: int (*side_one) = { { white_l1,... (6 Replies)
Discussion started by: Azrael
6 Replies

10. Programming

Looping an array of 2d arrays in C

Le sigh... Hopefully this will be the last time I have to ask for help on this topic. For a while now I've been working with a 1d array that holds 2d arrays. For reference you can view here. Now I'm just trying to loop through the elements with the following: #include <stdio.h> void... (3 Replies)
Discussion started by: Azrael
3 Replies
ARRAY_INTERSECT_KEY(3)							 1						    ARRAY_INTERSECT_KEY(3)

array_intersect_key - Computes the intersection of arrays using keys for comparison

SYNOPSIS
array array_intersect_key (array $array1, array $array2, [array $...]) DESCRIPTION
array_intersect_key(3) returns an array containing all the entries of $array1 which have keys that are present in all the arguments. PARAMETERS
o $array1 - The array with master keys to check. o $array2 - An array to compare keys against. o $... - A variable list of arrays to compare. RETURN VALUES
Returns an associative array containing all the entries of $array1 which have keys that are present in all arguments. EXAMPLES
Example #1 array_intersect_key(3) example <?php $array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); $array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); var_dump(array_intersect_key($array1, $array2)); ?> The above example will output: array(2) { ["blue"]=> int(1) ["green"]=> int(3) } In our example you see that only the keys 'blue' and 'green' are present in both arrays and thus returned. Also notice that the values for the keys 'blue' and 'green' differ between the two arrays. A match still occurs because only the keys are checked. The values returned are those of $array1. The two keys from the key => value pairs are considered equal only if (string) $key1 === (string) $key2 . In other words a strict type check is executed so the string representation must be the same. SEE ALSO
array_diff(3), array_udiff(3), array_diff_assoc(3), array_diff_uassoc(3), array_udiff_assoc(3), array_udiff_uassoc(3), array_diff_key(3), array_diff_ukey(3), array_intersect(3), array_intersect_assoc(3), array_intersect_uassoc(3), array_intersect_ukey(3). PHP Documentation Group ARRAY_INTERSECT_KEY(3)
All times are GMT -4. The time now is 11:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy