stupid question : if older compilers didnt add the /0 at the end of string for you but the ne wones do what happens if in a new compiler you add the /0 will the compiler add another to the end of that or does it know ones already there?
stupid question : if older compilers didnt add the /0 at the end of string for you but the ne wones do what happens if in a new compiler you add the /0 will the compiler add another to the end of that or does it know ones already there?
@lithium: Please explain how you get a buffer overflow from using strcmp().Originally posted by lithium
also never use:
strcpy
strcmp
or functions similar to those. instead use:
strncpy
strncmp
this will aviod buffer overflows (segmentation faults).
For those that aren't aware, strncpy() isn't guaranteed to null terminate the array.
Code:/* * The error here is that use programmer expected * strncpy() to make s equal BBBB\0 or BBBBB\0. * See the results below to see what actually happens. */ #include <string.h> #include <stdio.h> int main(void) { char s[10] = "aaaaaaaa"; puts(s); strncpy(s, "BBBBBBBB", 5); puts(s); } /* Output: aaaaaaaa BBBBBaaa */
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
Ah, why should I have assumed that *everyone* would be using the latest version of gcc? (kidding, but yeah I was not thinking of that at all)Originally posted by Thantos
Considering that a good number of students are using a Borland compiler from the 1980s I'd say that there is a good chance.