LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

change a string in a subfunction

I have a string and i want to change the original string in a seperate function. So i thought about a reference on this string, but it doesn't work. How can i change a string in a seperate function? I'm using LabWindow/CVI 6.0

Thanks Paco
0 Kudos
Message 1 of 6
(3,531 Views)
Can you be more explicit about your task, and maybe send an attachment of what you have tried to do, so that I can check out why it is not working?

Hi!
0 Kudos
Message 2 of 6
(3,523 Views)
I have two functions.

void func1(...)
{
char string[10]="";
char *pstring = &string[1];
func2(string);
SetCtrlCal(panelHandle, PANEL_StringOut, pstring); //StringOut should be ABBA
}

void func2(char &test[10])
{
int a=65,b=66,c=66,d=65;
test[1]=(char)a;
test[2]=(char)b;
test[3]=(char)c;
test[4]=(char)d;
}

I want to write something into the string in func2, and i need this string also in func1.

Message Edited by Paco on 05-19-2005 07:15 AM

0 Kudos
Message 3 of 6
(3,524 Views)
First, remember that the first element of an array in C has index zero. I would suggest for your sanity that you start there. Second, don't forget the null byte terminator on the end of a string. So your code should look like (my changes in bold😞

void func1(...)
{
char string[10]="";
char *pstring = &string[0]; //or just char *pstring = string;
func2(string);
SetCtrlCal(panelHandle, PANEL_StringOut, pstring); //StringOut should be ABBA
}

void func2(char test[10]) // note deleted &
// or void func2(char *test)
// or void func2(char test[])
{
int a=65,b=66,c=66,d=65;
test[0]=(char)a;
test[1]=(char)b;
test[2]=(char)c;
test[3]=(char)d;
test[4]='\0';
}


Martin.
--
Martin
Certified CVI Developer
0 Kudos
Message 4 of 6
(3,512 Views)
First of all, when you pass a string to a function, you should do like this:

void MyFunction(char *parameter_string) {
//function body
}

If, calling this function, you want to "be sure" to pass the first element, you do this:

MyFunction( &my_string[0] );

this way you pass the first element, and it's the same of

MyFunction( my_string );

Hope it helps!
0 Kudos
Message 5 of 6
(3,503 Views)
Thanks you helped mit alot.

Paco
0 Kudos
Message 6 of 6
(3,499 Views)