LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

strtok function returns NULL value

I am using Labwindows CVI to use a experimental equipment. And I made a code but there is a error.

treadbuff value is 0x06818A30 "" However, strtok function returns NULL value so error happens in the last row.

I don't know what is wrong here.

 

#define MAX_COMM_LEN 128   
char *tbuff; 
char *treadbuff;  
double tcurrent;     

treadbuff = (char*)malloc(MAX_COMM_LEN*sizeof(char)); 

memset(treadbuff, 0x0, MAX_COMM_LEN);  

tbuff = (char*)malloc(MAX_COMM_LEN*sizeof(char));               
memset(tbuff, 0x0, MAX_COMM_LEN);

tbuff = strtok (treadbuff, "A,");
tcurrent = atof(tbuff);
0 Kudos
Message 1 of 2
(3,620 Views)

This is not an error, this is the expected behavior: if you read the manual (which I strongly recommend Smiley Wink ) you'll see that strotk () returns NULL if no token can be found is the string. Since your string is empty it is expected that it returns NULL. You must check the return value on every call to strtok. See timeaxis examples that ships with cvi for a sample use of the function.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 2
(3,590 Views)