Borland C++ bug?

David A Whittemore del at percheron.ecn.purdue.edu
Wed Jun 19 10:30:26 AEST 1991


i often use sprintf() to append an existing char[] with another:

        char    line[BIG ARRAY], word[SMALLER ARRAY];

        until EOF
                fscanf(fp, "%s", word);
                sprintf(line, %s %s", line, word);

under Microsoft 5.1 and all other (BSD/SYSV) compilers i have used
this would logically append "line" with "word".

under borland C++ 2.0, however, the line:
        sprintf(line, "%s %s", line, word);

acts like:
        strcpy(line, word) !

which means it wipes out the existing contents of "line".

example:
        char    jnk[100];
        strcpy(jnk, "hello");
        sprintf(jnk, "%s %s", jnk, "world");

        yields (under borland): " world"

is this a borland bug, or have i been making some bad
assumptions as to how sprintf() works for years?

ug.

-david



More information about the Comp.lang.c mailing list