08-05-2008 02:31 PM
08-05-2008 03:11 PM
08-05-2008 03:13 PM
why would that be an odd question? I'm converting Labview code to C code.
08-05-2008
03:16 PM
- last edited on
01-29-2025
08:27 AM
by
Content Cleaner
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.
08-05-2008 03:32 PM
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.
08-05-2008 03:44 PM - edited 08-05-2008 03:49 PM
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() 🙂
08-05-2008 03:53 PM
The Wikipedia entry I pointed out seems easier. strncat instead of a for-loop.
@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() 🙂
08-05-2008 03:54 PM