Sponsored Content
Top Forums Programming [ C ] multidemensional array pass to functions Post 302265337 by VRoemer on Saturday 6th of December 2008 05:10:54 PM
Old 12-06-2008
Ow yes that does look like an issue

Alright so here are my updates, I was also thinking that I need to change my command line ascii codes to actual integers like this.

Now I'm coming to think that this could perhaps lead to some memory issues, so I might also be obligated to throw in a *alloc.

Code:
int main( int argc, char** argv )
{
    int i = 3; // start with the 3rd value of argv
    int** crc_s; 
    
    // Some argument testing here

    while( argv[ i ] ) {
       crc_s[ i ] = malloc( sizeof(argv[i]) );
       if( crc_s[ i ] == NULL )
           exit( -1 );
       crc_s[ i ] = atoi( argv[ i ] ); // Perhaps this is a better way of doing it
    }

    crcSpoof( argv[1], argv[2], "fileOutTmp", NULL, NULL, crc_s );

Hopefully thats the proper way to allocate memory ( I have never really done much with allocating memory )

Last edited by VRoemer; 12-06-2008 at 06:19 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Pass by reference in shell functions

Hi all, In windows script, passing arguments can be done in both "call by value" and "call by reference". Refer http://www.commandline.co.uk/lib/treeview/index.php Can we have call by reference in unix too? Thanks in adavance, Sonal. (5 Replies)
Discussion started by: sonaluphale
5 Replies

2. UNIX for Dummies Questions & Answers

How To Pass an Array Variable

Hi, I have a master BASH shell script where I define a bunch of variables: $var1=why $var2=is $var3=(this so hard) I would then like to call another shell script and pass these variables to it: $script2 $var1 $var2 $var3 This works fine for var1 and var2. However, var3 is an array,... (9 Replies)
Discussion started by: msb65
9 Replies

3. Shell Programming and Scripting

Tricky array substitution in functions

Hello, Please tell me if there is a better way to get the number of elements from an array that is passed to a function. This is what works on Solaris 8 (ksh) but it looks odd: loop_array() { array_name=$2 b1='\${\#' b2='}' nr_elements=`eval echo... (6 Replies)
Discussion started by: majormark
6 Replies

4. UNIX for Dummies Questions & Answers

How to pass array as an arguement ?

Hi experts, I am here again with another Issue. I need to pass the array as parameter / argument to another script. I tried it as follows . ( I got this idea from the link ) $ cat test1.sh #! /usr/bin/ksh set -a arr1 echo "...In Test1...." arr1="APPS_DEV" arr1="TEST_DEV" echo... (16 Replies)
Discussion started by: rajavu
16 Replies

5. Shell Programming and Scripting

Passing array to functions in ksh script

Let me know if there is a way to pass array to a funtion in ksh script. function isPresent { typeset member member=$1 dbList=$2 echo '$1:' $1 echo '$2' $dbList The array will be at the second position....something like this isPresent 12 <array> if then echo... (3 Replies)
Discussion started by: prasperl
3 Replies

6. Shell Programming and Scripting

Pass parameters to a function and running functions in parallel

Hi , I have a script which is using a text file as I/P. I want a code where it reads n lines from this file and pass the parameters to a function and now this script should run in such a way where a function can be called in parallel with different parameters. Please find below my script, it... (1 Reply)
Discussion started by: Ravindra Swan
1 Replies

7. Shell Programming and Scripting

Need help on Assigning a Array variable from Background Functions

I have a question on how can I assign a output of a function to a variable which is executed in background. Here is my example $ cat sample_program.sh #!/bin/ksh exec_func () { sleep 1 v=`expr $1 + 100` print $v } export OUT_ARR date for i in 1 2 do OUT_ARR=`exec_func $i` &... (1 Reply)
Discussion started by: mohan_kumarcs
1 Replies

8. Shell Programming and Scripting

Pass array to a function and display the array

Hi All I have multiple arrays like below. set -A val1 1 2 4 5 set -A val2 a b c d . . . Now i would like to pass the individual arrays one by one to a function and display/ do some action. Note : I am using ksh Can you please advise any solution... Thanks in advance. (7 Replies)
Discussion started by: Girish19
7 Replies

9. UNIX for Dummies Questions & Answers

How to pass first array value?

Hi, I am creating filesystem for block device, but I want to pass array value one by one acording to block device count. $tmp1 = block device count 3 $blockdevice = So I want to first pass sdb1 alone in loop, how to take only block device seprately from $blockdevice array. (1 Reply)
Discussion started by: stew
1 Replies

10. Programming

Code review: recursion in circular array, reduce two functions to one?

Hello, I think there's an easier way to do this but can't seem to recall but given an array of animals and an initial value is a random index in the array, here it's 3. 3,4,5,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0... inifinite repeat a quick brute force solution i came up with was two functions, i... (6 Replies)
Discussion started by: f77hack
6 Replies
XSetCommand(3X11)						     MIT X11R4							 XSetCommand(3X11)

Name
       XSetCommand, XGetCommand - set or read a window's WM_COMMAND property

Syntax
       XSetCommand(display, w, argv, argc)
	  Display *display;
	  Window w;
	  char **argv;
	  int argc;

       Status XGetCommand(display, w, argv_return, argc_return)
	  Display *display;
	  Window w;
	  char ***argv_return;
	  int *argc_return;

Arguments
       argc	 Specifies the number of arguments.

       argc_return
		 Returns the number of arguments returned.

       argv	 Specifies the application's argument list.

       argv_return
		 Returns the application's argument list.

       display	 Specifies the connection to the X server.

       w	 Specifies the window.

Description
       The function sets the command and arguments used to invoke the application.  (Typically, argv is the argv array of your main program.)

       can generate and errors.

       The function reads the WM_COMMAND property from the specified window and returns a string list.	If the WM_COMMAND property exists, it is
       of type STRING and format 8.  If sufficient memory can be allocated to contain the string list, fills in the argv_return and argc_return
       arguments and returns a non-zero status.  Otherwise, it returns a zero status.  To free the memory allocated to the string list, use

Properties
       WM_COMMAND
		 The command and arguments, separated by ASCII nulls, used to invoke the application.

Diagnostics
       The server failed to allocate the requested resource or server memory.

       A value for a Window argument does not name a defined Window.

See Also
       XAllocClassHint(3X11), XAllocIconSize(3X11), XAllocSizeHints(3X11), XAllocWMHints(3X11), XSetTransientForHint(3X11), XSetTextProp-
       erty(3X11), XSetWMClientMachine(3X11), XSetWMColormapWindows(3X11), XSetWMIconName(3X11), XSetWMName(3X11), XSetWMProperties(3X11), XSetWM-
       Protocols(3X11), XStringListToTextProperty(3X11)
       X Window System: The Complete Reference, Second Edition, Robert W. Scheifler and James Gettys

																 XSetCommand(3X11)
All times are GMT -4. The time now is 01:49 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy