LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

What is the equivalent C function of the "String Subset"

So i havnen't wrote C code since my freshman year in school and i've forgotten everything.
 
Is there an equivalent C function that is like the "String Subset" function used in Labview?
 
Thanks
0 Kudos
Message 1 of 8
(4,680 Views)
Well, that's certainly an odd questions. Why in the world would you need to know that? For whatever it's worth, look here.
Message 2 of 8
(4,668 Views)

why would that be an odd question?   I'm converting Labview code to C code.

 

0 Kudos
Message 3 of 8
(4,665 Views)

Why? Are you trying to use this on a microprocessor, or is this for something else? If it's for a microprocessor, NI has a tool for that. Perhaps it would be easier for you to just create a DLL out of the LabVIEW code and call that rather than rewriting it.

 
Message 4 of 8
(4,659 Views)

no, its for something else.  i'm talking to a device through Serial Communication and all the code has to be in C it's a requirment.

I basically need to look at the string of data, cut all of it out except for the last sentence, and then compare that last sentence with what i expect it to be to make sure it's correct.

In labview i just took the length of the data from the Serial port minus the lenth of the data for my vaiable of what I expect it to be and used that for the offset  and passed that into the "string subset" along with the serial data string.

0 Kudos
Message 5 of 8
(4,652 Views)

char* string_subset(char* str, int offset, int length)
  {
  char* substr;
  if((substr = (char*)malloc(length+1)) == NULL)
    return NULL;
  int i;
  for(i=0;i<length;i++)
    substr[i] = str[offset+i];

  substr[length]=0;
  return substr;
  }

Something like that?  Don't forget to free() 🙂



Message Edited by jorgewpi on 08-05-2008 03:49 PM
0 Kudos
Message 6 of 8
(4,649 Views)

@jorgewpi wrote:

char* string_subset(char* str, int offset, int length)
  {
  char* substr;
  if((substr = (char*)malloc(length+1)) == NULL)
    return NULL;
  int i;
  for(i=0;i
    substr[i] = str[offset+i];

  substr[length]=0;
  return substr;
  }

Something like that?  Don't forget to free() 🙂


The Wikipedia entry I pointed out seems easier. strncat instead of a for-loop. Smiley Wink
Message 7 of 8
(4,641 Views)
cool thanks guys.  I'll see if i can make this happen.  It's crazy how much you forget if you don't use it.
0 Kudos
Message 8 of 8
(4,635 Views)