LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I append two strings in Labwindows?Say,one is constant string and second one is variable string

Ex:Inppts
string1 is ABC_
string2 is i

outputs should be ABC_1,ABC_2..........
0 Kudos
Message 1 of 4
(5,677 Views)
There are several ways to get this done in CVI. One way is to use the Fmt function like in the following way:

#include
#include
#include

int main (int argc, char *argv[])
{
char constant_string[]="ABC_";
char variable_string[250];
char target_string[255];

int i=0;

if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */

for (i=0; i<10; i++)
{
// write to variable_string
Fmt (variable_string, "%s<%d", i);
// append variable_string to constant_string and store result in target_string
Fmt (target_string, "%s<%s%s", constant_string, variable_string);
printf ("%s\n", target_string);
}
return 0;
}

Regards,
Heinrich Illig
National Instruments Germany GmbH
Message 2 of 4
(5,677 Views)
Thanks Heinrich. It works great to me.
0 Kudos
Message 3 of 4
(5,677 Views)
Here's a method that will work in any ANSI C compiler.

char outputString[256];
char string1[250];
int i;

strcpy(string1, "ABC_");

for (i=1; i<=10; i++)
{
sprintf(outputString, "%s%d", string1, i);
/* whatever you want to do with outputString */
}
0 Kudos
Message 4 of 4
(5,677 Views)