trying to pass a string


 
Thread Tools Search this Thread
Top Forums Programming trying to pass a string
# 1  
Old 10-16-2005
trying to pass a string

hey guys,

I have a function that I need to pass something like this to:

function(set=a);

so the "set=" part is always the same, but I'm getting the "a" part in a for loop.

so the calls would be in a loop and would end up doing:

function(set=a);
function(set=b);
function(set=c);
etc.....


So how can I pass this to a for loop?

for ( i=0; i< setlist; i++) {
function(???);
}


I can't figure out how to pass in "set=[i]" without it treating the [i] literally.

Thanks
Annie
# 2  
Old 10-17-2005
Are you really passing a value to the function as "set=a"? Or are you going to be using the variable "set" in your function to hold the value that you are sending in to it (the values being a,b,c and so on)?

Also, you mention that you are getting the "a part in a for loop". Does this mean that the variables are stored in an array?

I can give you an answer based on the above two assumptions:
Code:
function(variable_type set) {

/*do processing here*/

}
.
.
for(i=0;i<setlist;i++) {
function(some_array[i]);
}
.
.

If this is not what you are looking for, you need to describe the problem better or post some code.
# 3  
Old 10-17-2005
Hi sorry I wasn't clear.

I'm actually want to pass the string "set=a", "set=b", "set=c", etc....to the function. The "set=" part always stays the same but a, b, c...etc. change which is the part I can't figure out how to deal with.

so I would so something like:

function("set=a");


and then function is:

function(char *string) {

printf("string is %s\n", string);
}
# 4  
Old 10-17-2005
Code:
/* added datatype to "function" */
#include <stdlib.h>

void function(char *string) 
{
    printf("string is %s\n", string);
}
int main(void)
{	
    char value='a';
    char tmp[24]={0x0};
    int i=0;
    /* loop thru all 26 lowercase letters */
    for(value='a', i=0;i<26;i++)
    {
        sprintf(tmp,"set=%c",value++);
        function(tmp);
    }
    return 0;
}

# 5  
Old 10-17-2005
thanks so much! that is perfect.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pass string into sql query?

Hi Gurus, I have a request which needs to pass string into sql. dummy code as below: sqlplus -s user/password@instance << EOF >>output.txt set echo off head off feed off pagesize 0 trimspool on linesize 1000 colsep , select emp_no, emp_name from emp where emp_no in ('a', 'b', 'c'); exit;... (4 Replies)
Discussion started by: ken6503
4 Replies

2. Shell Programming and Scripting

Pass string to nummerical value in tcsh

I want to compare two values for Value A and ValueB, however, they are strings, so is there a way I could them into numberical value in tcsh #! /bin/tcsh set ValueA = `awk '{print $6}' out0File` set ValueB = `awk '{print $6}' out1File` set Delta = `expr $ValueA - $ValueB` ... (1 Reply)
Discussion started by: proteinpi
1 Replies

3. Ubuntu

How to pass string to another PC in LAN

Need to send string from Ubuntu to Windows XP? It contains URL. If not for XP may be somebody knows how send to another Ubuntu PC. (1 Reply)
Discussion started by: Yola
1 Replies

4. Programming

How to pass int and return string in C?

hi I want to write a function which takes int as input and returns a string like this. char GetString(int iNo) { switch(iNo) { case 0: return "Zero"; break; case 1: return "One"; break; } } void main() { int i; printf("Enter... (1 Reply)
Discussion started by: atharalikhan
1 Replies

5. Shell Programming and Scripting

Pass string arg from shell to perl

My shell script generates a bunch of lines of text and passes this text as an argument to a perl script. I'm able to do this, but for some reason newlines don't get recognized in the perl script and so the script just prints actual '\n' instead of carriage returning, otherwise everything gets... (3 Replies)
Discussion started by: stevensw
3 Replies

6. Shell Programming and Scripting

How to pass string as a parameter in a script

Hi friends. i am newbie to shell scripting. I need to create a script where i will be passing 2 parameters to the script and based on that it should work. For ex: start_proc a 2 or start_proc b 2 start_proc a 2 --- this should bring up 2 processes as i define inside the script. start_proc... (2 Replies)
Discussion started by: friscouser
2 Replies

7. Shell Programming and Scripting

Not able to pass string with spaces in shell

I have to pass a sentence in a file, the specs are as: cat run | sed 's/SRT/'$8'/g' | sed 's/plength/68/g' | sed 's/stcol/'$5'/g' | sed 's/encol/'$6'/g' | sed 's/brdtype/'$1'/g' | sed 's/brdtxt/'$3'/g' | sed 's/demotxt/Total '$2'/g' | sed 's/bantxt/ban_'$7'/g' | sed 's/validcodes/'$4'/g' >... (15 Replies)
Discussion started by: patilrakesh1984
15 Replies

8. Shell Programming and Scripting

Pass a string with spaces to a shell script

I'm a beginner and wasn't able to google my problem... I would like to pass a string with spaces to a shell script. my test_shell: #!/bin/sh -vx ####################################################### # generate_documentation (c) Ch.Affolter Nov. 2009 Version 1.0 #... (3 Replies)
Discussion started by: vivelafete
3 Replies

9. Shell Programming and Scripting

Pass string from shell script to java

Hi, I,m writing a program in shell script and currently this script is calling a java program. I have a problem to pass string variable from my shell script to the java program. I don't know on how to pass it and how the java program can call what I have pass from the shell script. This is... (3 Replies)
Discussion started by: badbunny9316
3 Replies

10. Programming

pass char string via system()

hello all i am trying to pass a argument through system function to a shell script. #shell script echo.sh to display the string echo $1 and the c program is. #include<stdlib.h> int main() { const char *str = "hello all"; system("sh echo.sh str"); } the output i... (5 Replies)
Discussion started by: zius_oram
5 Replies
Login or Register to Ask a Question