Hi guys!
I'm trying to rid my words of newline characters (and eventually punctuation as well). The words are in a two-dimensional array declared as words[MAXWORD][MAXLINE], where MAXWORD is currently 8000, and MAXLINE is currently 20. So up to 8000 words of 20 characters each.
To do this, I am parsing the array character by character, and only copying the character into a new array cleanwords if it *isn't* '\n'. Then I print out the cleanwords array, and it *should* be rid of '\n'. However, it is coming out exactly the same.
I put in some counters to keep track of how many operations are occurring, k for the number of times a character *isn't* a '\n', and l for the number of times a character *is* a '\n'. To my surprise, k is 6602 and l is 38. Now 38 is the number of lines in the text file I'm using, so I figure I must be on the right track -- the error must lie somewhere within the copying process -- for some reason, the '\n' are still migrating to the clean array.
I have been looking at this for some time, and I just can't see the problem. If you can tell me what I'm doing wrong, then I'd be very grateful.
Thanks and much love,
sd
char words[MAXWORD][MAXLEN];
char cleanwords[MAXWORD][MAXLEN];
char buff[BUFSIZ];
int ntokens = 0;
int i, j, k, l;
[B]...[/B]
for (i = 0; i < ntokens; i++) {
for (j = 0; j < sizeof(words[i]); j++) {
if (words[i][j] != '\n') {
cleanwords[i][j] = words[i][j];
k++; ;
}
else {
l++;
}
}
}