Dumb question; If I use the code snipit below, what happens if token is NULL ('\0')?
char *token;
token=strtok(buffer,':');
while (token)
{
statement 1;
}
Dumb question; If I use the code snipit below, what happens if token is NULL ('\0')?
char *token;
token=strtok(buffer,':');
while (token)
{
statement 1;
}
Hi Everyone,
Just joined. I'm from Central Wisconsin in the U.S. and I'm an IT professional with 27 years in the industry.
I am primarily an Infrastructure person as I have supported AD, Networks, Win-PC/Servers, Tandems, VAX's, HP-Unix and AS/400s. Through it all I have had need to write code occassionally so I taught myself C for its portability and I have used it on most of the platforms I have supported. However, since I am self-taught, I don't consider myself very good at C. I did start life as a Software Engineer, so I do know a few other languages including PL/M, FORTRAN, VB, Java, PERL and the various control languages from the various platforms. Additionally, I have supported some pretty extensive networks and having grown up with networking, I have a pretty wide breath of knowledge going back to modems, through FDDI and Ethernet topologies.
Hobbies (besides staying warm in the Winter) include most outdoor activities such as golf and fishing. Additionally, I love reading, music, woodworking, welding, working on my tractor, etc.
Take care, Jay
Hi,
I've been developing some code that parses output reports and re-reports on information that is of interest. I utilize strtok quite heavily in this program and I have run into the situation where my final strtok call may or may not return some info. Depending on if there is info returned will dictate my branch in an IF statement. Code snipit:
while (fgets(buffer, 133, ofp) != NULL)
{
if (!strncmp(&buffer[1], "Queue:", 6))
{
memset(oqnamlib,'\0',sizeof(oqnamlib));
if (strncmp(&buffer[10]," ",10))
{
strncpy(que,&buffer[10],10);
token=strtok(buffer," ");
token=strtok(NULL," :");
token=strtok(NULL,":");
token=strtok(NULL," :");
len = strlen(&token[0]);
if (len <= 0)
If the last call to strtok does not find anymore info, i.e. token becomes NULL, then if I do the strlen call the code blows up at runtime. token is defined as char *token. I have tried the strlen command with token, *token (doesn't compile), &token and &token[0]. Any suggestions?
{