char *tchr = NULL;
strcpy(tmp, DData.no.value.string);
tchr = strchr(tmp, '-');
if (tchr == NULL) { /* no '-' in string */
} else {
*tchr = '\0';
/* str is now truncated */
}
above is what I tried, but keep getting an error on "tchr = strchr(tmp, '-');. Below is the error...
warning C4047: '=' : 'int *' differs in levels of indirection
what am I missing?
thanks again
Main Topics
Browse All Topics





by: SaltePosted on 2003-06-02 at 09:16:40ID: 8630657
if you can destroy the original string simply replace the character '-' with a '\0' (NUL character) this will effectively terminate the string at the new place.
If you cannot destroy the original string use strncpy() or memcpy() to copy the partial string to new buffer and in the case of memcpy() do an explicit assignment of the character past the end to '\0'.
For example if you want to truncate the string after the first '-':
char * p = strchr(str, '-');
if (p == NULL) { /* no '-' in string */
} else {
*p = '\0';
/* str is now truncated */
}
char * p = strchr(str, '-');
if (p == NULL) { /* no '-' in string */
} else {
memcpy(other_str, str, p - str);
other_str[p - str] = '\0';
/* other_str is now the str truncated */
}
Hope this is of help.
Alf