July 22nd, 2003, 10:05 PM
memory free() error
how come I get an error if I try to free p. It compiles if I don't try to free it.
i = oVector ;
j = oVector - i ;
p = (char*) malloc(sizeof(char)* j);
strncpy(p,line + (i), j);
p[j] = '\0';
keywords = false;
printf("this prints \n");
Some day I'll create a smart quote to put here.
July 22nd, 2003, 10:45 PM
What error are you getting?
"Me fail English? That's unpossible!"
July 22nd, 2003, 10:47 PM
BTW you also have a bug here:
p[j] = '\0';
This should be
p[j-1] = '\0';
since arrays in C are 0 based. If you allocate a 100 element array, it has element indices from p...p. You may have a similar problem with the strncpy statement above that.
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne
"I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
July 22nd, 2003, 11:30 PM
thanks guys, it was the error that scorpion pointed out that I overlooked. I don't think I have an error in the strncpy. strncpy is not zero base so strncpy(p1, p2, 8) is not gonna copy 9 chars. If I'm overlooking something, scorp, feel free to pointer it out.
You guys always have the answers.