sprintf 질문

nowhere1122의 이미지

sprintf 값

pid[i] = fork();
if (pid[i] == 0) /* child */
{
/* do exec stuff */

child = i+1;
sprintf(temp_buffer,"%d",child);
args[2] = temp_buffer;
/*sprintf(temp_buffer,"%d",row);
args[3] = temp_buffer;
sprintf(temp_buffer,"%d",col);
args[4] = temp_buffer; */
sprintf(temp_buffer,"%d",row);
args[3] = temp_buffer;
sprintf(temp_buffer,"%d",col);
args[4] = temp_buffer;
printf("atoi:::child:%d, row:%d, col:%d\n",atoi(args[2]), atoi(args[3]),atoi(args[4]));
printf("string:::child:%s, row:%s, col:%s\n",args[2], args[3],args[4]);
printf("int:::child:%d, row:%d, col:%d\n",child, row,col);

execv("./child-matrix", args);

shmdt(buffer);
sleep(1);
exit(0);
}
else if (pid[i] < 0)
{
printf("Failed to create process %i\n", i);
}

fork 한다음 child, row, col 값을 string으로 변환하는데 변환하면 값이 다르게 나요네요
int:::child 1 row 0 col 0
string::: child 0 row 0 col 0
atoi::: child 0 row 0 col 0

왜 다르게 나오는지 전혀 모르겠네요;;;;;

익명 사용자의 이미지

args[2], args[3], args[4] 모두, 동일한 temp_buffer를 가리키고 있으니까요.