Sponsored Content
Top Forums Programming Calling an array of arrays in C. Post 303023139 by Azrael on Wednesday 12th of September 2018 10:48:59 AM
Old 09-12-2018
Thank you for the answer back. It does seem that **side[s][t] = randval helped resolve that part of the problem. Before I go over what's left I changed the last [] to ROW as it should only have three for the three {} in these I guess:
Code:
int (*side_one[MATRIX][MATRIX])[ROW] = { { white_l1, white_l2, white_l3 }, { white_m1, white_m2, white_m3 }, { white_r1, white_r2, white_r3 } };

So I have a define for that as '3' and these are my warnings/errors now:

Code:
$ gcc test.c -o test
test.c: In function ‘main':
test.c:457:39: warning: passing argument 1 of ‘fillit' from incompatible pointer type [-Wincompatible-pointer-types]
      fillit((side_one[MATRIX][MATRIX])[ROW]);
                                       ^
test.c:54:19: note: expected ‘int * (*)[1000][3]' but argument is of type ‘int *'
 void fillit(int *(side[MATRIX][MATRIX])[ROW]){
             ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~

Not really sure. I've tried moving around the * signs inside and outside of the parenthesis. Even tried removing them. Basically I've tried to brute-force this problem, but I seem to get the same results.

Thanks for help with the pointer to the pointer though!
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. Shell Programming and Scripting

PHP arrays as array elements

PHP question...I posted this on the Web Development forum, but maybe this is a better place! I have an SQL query that's pulled back user IDs as a set of columns. Rather than IDs, I want to use their names. So I have an array of columns $col with values 1,7,3,12 etc and I've got an array $person... (3 Replies)
Discussion started by: JerryHone
3 Replies

4. 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

5. Shell Programming and Scripting

perl - need help with 2 arrays to hash or 2d array?

I have 2 arrays: @array1 outputs the following: 1 1 1 2 @array2 outputs the following A B C D (2 Replies)
Discussion started by: streetfighter2
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

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

8. Programming

Making an array of 2D arrays in C

I hate I'm asking for help again. Unfortunately it seems there just aren't any links I can find on making an array that holds a bunch of two dimensional arrays. Maybe my google-fu is lacking. Basically I have a header file like this: #define MATRIX 10 int white_l1; int white_l2; int... (2 Replies)
Discussion started by: Azrael
2 Replies

9. 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

10. UNIX for Beginners Questions & Answers

Multiply elements of 2 arrays together into another array

So I need to Write an array processing program using a Linux shell programming language to perform the following. Load array X of 20 numbers from an input file X. Load array Y of 20 numbers from an input file Y. Compute array Z by multiply Xi * Yi then compute the square-root of this... (2 Replies)
Discussion started by: sarapham409
2 Replies
LOCK(7) 							   SQL Commands 							   LOCK(7)

NAME
LOCK - explicitly lock a table SYNOPSIS
LOCK [ TABLE ] name [, ...] LOCK [ TABLE ] name [, ...] IN lockmode MODE where lockmode is one of: ACCESS SHARE | ROW SHARE | ROW EXCLUSIVE | SHARE UPDATE EXCLUSIVE | SHARE | SHARE ROW EXCLUSIVE | EXCLUSIVE | ACCESS EXCLUSIVE INPUTS name The name (optionally schema-qualified) of an existing table to lock. ACCESS SHARE MODE This is the least restrictive lock mode. It conflicts only with ACCESS EXCLUSIVE mode. It is used to protect a table from being mod- ified by concurrent ALTER TABLE, DROP TABLE and VACUUM FULL commands. Note: The SELECT command acquires a lock of this mode on referenced tables. In general, any query that only reads a table and does not modify it will acquire this lock mode. ROW SHARE MODE Conflicts with EXCLUSIVE and ACCESS EXCLUSIVE lock modes. Note: The SELECT FOR UPDATE command acquires a lock of this mode on the target table(s) (in addition to ACCESS SHARE locks on any other tables that are referenced but not selected FOR UPDATE). ROW EXCLUSIVE MODE Conflicts with SHARE, SHARE ROW EXCLUSIVE, EXCLUSIVE and ACCESS EXCLUSIVE modes. Note: The commands UPDATE, DELETE, and INSERT acquire this lock mode on the target table (in addition to ACCESS SHARE locks on any other referenced tables). In general, this lock mode will be acquired by any query that modifies the data in a table. SHARE UPDATE EXCLUSIVE MODE Conflicts with SHARE UPDATE EXCLUSIVE, SHARE, SHARE ROW EXCLUSIVE, EXCLUSIVE and ACCESS EXCLUSIVE modes. This mode protects a table against concurrent schema changes and VACUUM runs. Note: Acquired by VACUUM (without FULL). SHARE MODE Conflicts with ROW EXCLUSIVE, SHARE UPDATE EXCLUSIVE, SHARE ROW EXCLUSIVE, EXCLUSIVE and ACCESS EXCLUSIVE modes. This mode protects a table against concurrent data changes. Note: Acquired by CREATE INDEX. SHARE ROW EXCLUSIVE MODE Conflicts with ROW EXCLUSIVE, SHARE UPDATE EXCLUSIVE, SHARE, SHARE ROW EXCLUSIVE, EXCLUSIVE and ACCESS EXCLUSIVE modes. Note: This lock mode is not automatically acquired by any PostgreSQL command. EXCLUSIVE MODE Conflicts with ROW SHARE, ROW EXCLUSIVE, SHARE UPDATE EXCLUSIVE, SHARE, SHARE ROW EXCLUSIVE, EXCLUSIVE and ACCESS EXCLUSIVE modes. This mode allows only concurrent ACCESS SHARE, i.e., only reads from the table can proceed in parallel with a transaction holding this lock mode. Note: This lock mode is not automatically acquired by any PostgreSQL command. ACCESS EXCLUSIVE MODE Conflicts with all lock modes. This mode guarantees that the holder is the only transaction accessing the table in any way. Note: Acquired by ALTER TABLE, DROP TABLE, and VACUUM FULL statements. This is also the default lock mode for LOCK TABLE statements that do not specify a mode explicitly. OUTPUTS LOCK TABLE The lock was successfully acquired. ERROR name: Table does not exist. Message returned if name does not exist. DESCRIPTION
LOCK TABLE obtains a table-level lock, waiting if necessary for any conflicting locks to be released. Once obtained, the lock is held for the remainder of the current transaction. (There is no UNLOCK TABLE command; locks are always released at transaction end.) When acquiring locks automatically for commands that reference tables, PostgreSQL always uses the least restrictive lock mode possible. LOCK TABLE provides for cases when you might need more restrictive locking. For example, suppose an application runs a transaction at READ COMMITTED isolation level and needs to ensure that data in a table remains stable for the duration of the transaction. To achieve this you could obtain SHARE lock mode over the table before querying. This will pre- vent concurrent data changes and ensure subsequent reads of the table see a stable view of committed data, because SHARE lock mode con- flicts with the ROW EXCLUSIVE lock acquired by writers, and your LOCK TABLE name IN SHARE MODE statement will wait until any concurrent holders of ROW EXCLUSIVE mode commit or roll back. Thus, once you obtain the lock, there are no uncommitted writes outstanding; furthermore none can begin until you release the lock. Note: To achieve a similar effect when running a transaction at the SERIALIZABLE isolation level, you have to execute the LOCK TABLE statement before executing any DML statement. A serializable transaction's view of data will be frozen when its first DML statement begins. A later LOCK will still prevent concurrent writes --- but it won't ensure that what the transaction reads corresponds to the latest committed values. If a transaction of this sort is going to change the data in the table, then it should use SHARE ROW EXCLUSIVE lock mode instead of SHARE mode. This ensures that only one transaction of this type runs at a time. Without this, a deadlock is possible: two transactions might both acquire SHARE mode, and then be unable to also acquire ROW EXCLUSIVE mode to actually perform their updates. (Note that a transaction's own locks never conflict, so a transaction can acquire ROW EXCLUSIVE mode when it holds SHARE mode --- but not if anyone else holds SHARE mode.) Two general rules may be followed to prevent deadlock conditions: o Transactions have to acquire locks on the same objects in the same order. For example, if one application updates row R1 and than updates row R2 (in the same transaction) then the second application shouldn't update row R2 if it's going to update row R1 later (in a single transaction). Instead, it should update rows R1 and R2 in the same order as the first application. o If multiple lock modes are involved for a single object, then transactions should always acquire the most restrictive mode first. An example for this rule was given previously when discussing the use of SHARE ROW EXCLUSIVE mode rather than SHARE mode. PostgreSQL does detect deadlocks and will rollback at least one waiting transaction to resolve the deadlock. If it is not practical to code an application to follow the above rules strictly, an alternative solution is to be prepared to retry transactions when they are aborted by deadlocks. When locking multiple tables, the command LOCK a, b; is equivalent to LOCK a; LOCK b;. The tables are locked one-by-one in the order speci- fied in the LOCK command. NOTES LOCK ... IN ACCESS SHARE MODE requires SELECT privileges on the target table. All other forms of LOCK require UPDATE and/or DELETE privi- leges. LOCK is useful only inside a transaction block (BEGIN...COMMIT), since the lock is dropped as soon as the transaction ends. A LOCK command appearing outside any transaction block forms a self-contained transaction, so the lock will be dropped as soon as it is obtained. RDBMS locking uses the following standard terminology: EXCLUSIVE An exclusive lock prevents other locks of the same type from being granted. SHARE A shared lock allows others to also hold the same type of lock, but prevents the corresponding EXCLUSIVE lock from being granted. ACCESS Locks table schema. ROW Locks individual rows. PostgreSQL does not follow this terminology exactly. LOCK TABLE only deals with table-level locks, and so the mode names involving ROW are all misnomers. These mode names should generally be read as indicating the intention of the user to acquire row-level locks within the locked table. Also, ROW EXCLUSIVE mode does not follow this naming convention accurately, since it is a sharable table lock. Keep in mind that all the lock modes have identical semantics so far as LOCK TABLE is concerned, differing only in the rules about which modes conflict with which. USAGE
Obtain a SHARE lock on a primary key table when going to perform inserts into a foreign key table: BEGIN WORK; LOCK TABLE films IN SHARE MODE; SELECT id FROM films WHERE name = 'Star Wars: Episode I - The Phantom Menace'; -- Do ROLLBACK if record was not returned INSERT INTO films_user_comments VALUES (_id_, 'GREAT! I was waiting for it for so long!'); COMMIT WORK; Take a SHARE ROW EXCLUSIVE lock on a primary key table when going to perform a delete operation: BEGIN WORK; LOCK TABLE films IN SHARE ROW EXCLUSIVE MODE; DELETE FROM films_user_comments WHERE id IN (SELECT id FROM films WHERE rating < 5); DELETE FROM films WHERE rating < 5; COMMIT WORK; COMPATIBILITY
SQL92 There is no LOCK TABLE in SQL92, which instead uses SET TRANSACTION to specify concurrency levels on transactions. We support that too; see SET TRANSACTION [set_transaction(7)] for details. Except for ACCESS SHARE, ACCESS EXCLUSIVE, and SHARE UPDATE EXCLUSIVE lock modes, the PostgreSQL lock modes and the LOCK TABLE syntax are compatible with those present in Oracle(TM). SQL - Language Statements 2002-11-22 LOCK(7)
All times are GMT -4. The time now is 03:58 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy