Hi everyone I've got a problem with strtok_r
throwing in random new lines, and was wondering if anyone could show me why it would be doing that? From my understanding, it is printing a new line when the input has a new line at the end, but this doesn't happen every time and I'm not sure why. My motivation is to have an input string of multiple words, and for strtok_r
to store the words individually into an array (storage).
char delimit[] = " \t\r\n\v\f";
char *tempword; //temporary word until it is stored into the temp array
for (int r = 0; r < line_count; r++) {
int counting = 0; //location of where tempword is stored in temp[counting]
tempword = strtok_r(ptrarray[r], delimit, &ptrarray[r]);
while (tempword != NULL && strcmp(tempword,"\n") != 0 && strcmp(tempword, "\0") != 0) {
printf("temp: %s\n", tempword);
storage[r][counting] = strdup(tempword);
tempword = strtok_r(NULL, " ", &ptrarray[r]);
counting++;
}
storage[r][word_count] = NULL; //last argument = NULL for execvp function
}