Changing value inside function


 
Thread Tools Search this Thread
Top Forums Programming Changing value inside function
# 1  
Old 05-13-2012
Changing value inside function

I have the following code and want to update shiftDesc inside the function. Is it correct to declare the argument as:

Code:

int shiftDesc
Code:
void prValue_vd(
  FILE*  stream,           // name of output stream
  int  shift,              // amount of shift to the right
  const char*  value,      // value associated with argument action key
  int  shiftDesc,          // additional shift to the description
  const char*  desc ) {    // description

  shiftDesc = shiftDesc + 4;
  const char*  format = "%*s\e[1;32m%s\e[0;37m%*s%s\e[0m\n";
  fprintf( stream, format, shift, " " , value, shiftDesc, " ", desc );

}

# 2  
Old 05-13-2012
You want the new value to persist in the calling function, then you need to use pointers for shiftDesc.

Code:
int *shiftDesc,
...
*shiftDesc = *shiftDesc + 4

fprintf(..., *shiftDesc, ...);

call it using &shiftDesc (read as: "The address of"): prValue_vd(..., ..., ..., &intval, ...);
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help on awk for printing the function name inside each function

Hi, I am having script which contains many functions. Need to print each function name at the starting of the function. Like below, functionname() { echo "functionname" commands.... } I've tried like below, func=`grep "()" scriptname | cut -d "(" -f1` for i in $func do nawk -v... (4 Replies)
Discussion started by: Sumanthsv
4 Replies

2. Shell Programming and Scripting

Getopts inside a function is not working

Hi All, I am using geopts inside a function in shell script. But it is doesnt seem to read the input args and I always gt empty value in o/p. my code is http://sparshmail.ad.infosys.com/owa/14.2.318.4/themes/base/pgrs-sm.gif This message has not been sent. #!/bin/ksh IFS=' '... (1 Reply)
Discussion started by: prasperl
1 Replies

3. Shell Programming and Scripting

Call function inside CASE

i have a case statement which branches to different sections based on an input. Each branch needs to call a function. below is the code. FOr some reason, the code inside the function is not getting executed. the code is below for reference. in the below code echo "Function 1" which is there... (2 Replies)
Discussion started by: cvsanthosh
2 Replies

4. Shell Programming and Scripting

Troubles inside an envelope function

Hi all! I have a function (named "orig") that analyze web sites given from an argument, it works very well when by itself: #!/bin/bash chain="$1" echo chain $chain curl "$chaine" -o prop.txt ... and then it perform some analysis on the prop.txt It works flawlessly if I type: orig... (2 Replies)
Discussion started by: Zephyr
2 Replies

5. Shell Programming and Scripting

Last modified time of the folder is changing when I view the file inside the directory

Hi., Last modified time of the folder is changing when I view the file inside the directory. Here is the test on sample directory. I believe that ls -l commands gives the time detail w.r.t last modified time. Pl. suggest. bash-3.2$ mkdir test bash-3.2$ cd test bash-3.2$ touch myfile.txt... (2 Replies)
Discussion started by: IND123
2 Replies

6. Shell Programming and Scripting

CHANGING THE TEXT INSIDE A FILE

Hi All, I need a small help in formating a file. I have a file with word like this; ATGHYJIKOLFHJDHDGDYFGFYGRYGFYRHFYHFUED DHDJFDFSJFLFJSKJFSLKJFGHDKLGLDKGLKDNVNV VNLDVLDVDHFJDKDJVNVHSUFNHJFMVJFMVKJMFV ... .... ....like this 75000 words. I want to convert this words into a single... (5 Replies)
Discussion started by: Lucky Ali
5 Replies

7. Shell Programming and Scripting

Changing value of a variable inside a shell script

I have a continous polling happening inside a shell script on AIX. This actually calls a PL/SQL block. Is there a way I can set up a variable or pass an interrupt to end the script gracefully. I cant read from the config once the job starts running. Ideally I should change value of a variable and... (1 Reply)
Discussion started by: kshyju
1 Replies

8. Programming

Inline function inside Classes

#include <iostream> using namespace std; class A { public: int Getvalue() { return i;} private: int i; }; int main() {} The above code compiles properly in g++ or in any other C++ compiler. BUT, the variable 'i' is used (in 'return i' statement) before it is... (1 Reply)
Discussion started by: deepthi.s
1 Replies

9. Shell Programming and Scripting

value inside a function

i have a script like this #!/bin/ksh initialize() { x=20 } ... ... ... x=10 initialize; echo $x (2 Replies)
Discussion started by: trichyselva
2 Replies

10. Shell Programming and Scripting

calling function inside awk

Hi All, My 1.txt contains some functions fun1() .... .... fun2() .... .... I can call these fun from 2.txt inside awk as below value="`fun1 "argument1"`" awk 'BEGIN {printf ("%s", "'"$value"'")}' I need to modify the above code so that without using the variable to store... (2 Replies)
Discussion started by: jisha
2 Replies
Login or Register to Ask a Question