Strcpy() corrupts the copied string in Solaris but not Linux

Posted by strictlyrude27 on Stack Overflow See other posts from Stack Overflow or by strictlyrude27
Published on 2010-04-16T05:25:37Z Indexed on 2010/04/16 5:33 UTC
Read the original article Hit count: 325

Filed under:
|
|
|

Hi all,

I'm writing a C code for a class. This class requires that our code compile and run on the school server, which is a sparc solaris machine. I'm running Linux x64.

I have this line to parse (THIS IS NOT ACTUAL CODE BUT IS INPUT TO MY PROGRAM):

while ( cond1 ){

I need to capture the "while" and the "cond1" into separate strings. I've been using strtok() to do this. In Linux, the following lines:

char *cond = NULL;
cond = (char *)malloc(sizeof(char));
memset(cond, 0, sizeof(char));
strcpy(cond, strtok(NULL, ": \t\(){")); //already got the "while" out of the line

will correctly capture the string "cond1".Running this on the solaris machine, however, gives me the string "cone1".

Note that in plenty of other cases within my program, strings are being copied correctly. (For instance, the "while") was captured correctly.

Does anyone know what is going on here?

© Stack Overflow or respective owner

Related posts about solaris

Related posts about strcpy