H
Henryk Zabor
This is a silly newbie question.
Here is some (maybe bad) string tokenization code:
/* Tokenise a string */
char *tok = str;
char *p;
for (p=str; *p != '\0'; p++) {
if (*p == ' ') {
*p = '\0';
processToken(tok);
tok = (p+1);
}
}
processToken(tok);
So, a lot of \0 chars are put into the string. Does this hinder the
resource from being freed in the end? Can I still call free() for the
complete string?
I am actually a Java programmer, but have to learn C now. I guess my
biggest problem is how to use free(). When do I have to call free and when
is it not necessary? Where can I find this explained?
Thank you!
Henryk
Here is some (maybe bad) string tokenization code:
/* Tokenise a string */
char *tok = str;
char *p;
for (p=str; *p != '\0'; p++) {
if (*p == ' ') {
*p = '\0';
processToken(tok);
tok = (p+1);
}
}
processToken(tok);
So, a lot of \0 chars are put into the string. Does this hinder the
resource from being freed in the end? Can I still call free() for the
complete string?
I am actually a Java programmer, but have to learn C now. I guess my
biggest problem is how to use free(). When do I have to call free and when
is it not necessary? Where can I find this explained?
Thank you!
Henryk