K
Kenny M
I am trying to build a program written by a colleague and get an
'unresolved external' error when I run the Borland make utility
(offending function below). Any ideas what's wrong? I am not a c++
programmer so a simple solution would be very welcome.
/*
* strtoko.cpp
*
* Does exactly the same as the standard function "strtok", but
* also rebuilds the original string as it goes, but storing the
* separator which was overwritten with an end-of-string and
restoring
* it on the subsequent entry.
*
* Returns a pointer to the next symbol found, or NULL if end of
string.
*
* s i-o : string to be scanned.
* ct in : string containing all valid separators.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char *strtoko( char *s, const char *ct )
{ static char *localp, hold;
char *token;
if ( s != NULL )
localp = s;
else
{ if ( localp == NULL )
{ fprintf( stderr, "\nError in 'strtoko' : Called with NULL
prior " );
fprintf( stderr, "to a call with string for scanning.\n"
);
exit(1);
}
if ( hold == '\0' ) return( NULL );
*localp = hold;
localp++;
}
localp += strspn( localp, ct ); /* skip over any separator
characters */
if ( localp == '\0' ) return( NULL );
token = localp;
localp += strcspn( localp, ct ); /* skip to next separator (or
end-string)*/
hold = *localp;
*localp = '\0';
return( token );
}
'unresolved external' error when I run the Borland make utility
(offending function below). Any ideas what's wrong? I am not a c++
programmer so a simple solution would be very welcome.
/*
* strtoko.cpp
*
* Does exactly the same as the standard function "strtok", but
* also rebuilds the original string as it goes, but storing the
* separator which was overwritten with an end-of-string and
restoring
* it on the subsequent entry.
*
* Returns a pointer to the next symbol found, or NULL if end of
string.
*
* s i-o : string to be scanned.
* ct in : string containing all valid separators.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char *strtoko( char *s, const char *ct )
{ static char *localp, hold;
char *token;
if ( s != NULL )
localp = s;
else
{ if ( localp == NULL )
{ fprintf( stderr, "\nError in 'strtoko' : Called with NULL
prior " );
fprintf( stderr, "to a call with string for scanning.\n"
);
exit(1);
}
if ( hold == '\0' ) return( NULL );
*localp = hold;
localp++;
}
localp += strspn( localp, ct ); /* skip over any separator
characters */
if ( localp == '\0' ) return( NULL );
token = localp;
localp += strcspn( localp, ct ); /* skip to next separator (or
end-string)*/
hold = *localp;
*localp = '\0';
return( token );
}