[완료]sprintf에 관련한 질문입니다.

tatchi의 이미지

void function1(char** arg, char *str)
{
    char* tmp;
    int i=0;
 
    tmp = strstr(str, "hi");
 
    if(tmp != NULL)
    {
        while( tmp[i] != '\r' )
        {
            sprintf((*arg)+i, tmp[i]);
            i++;
        }
    }
}

void function1(char** arg, char *str)
{
    char* tmp;
    int i=0;
 
    tmp = strstr(str, "hi");
 
    if(tmp != NULL)
    {
        while( tmp[i] != '\r' )
        {
            sprintf((*arg)+i, tmp+i);
            i++;
        }
    }
}

위 두 함수 function1, function2는 어떤 차이가 있나요?

단지 function1 sprintf 내의 tmp[i]를 tmp+i로 바꿨을 뿐인데,
passing argument 2 of 'sprintf' makes pointer from integer without a case
라는 warning이 사라집니다.

저 둘의 차이를 사실 잘 모르겠습니다ㅠㅠ

익명 사용자의 이미지

tmp가 char* 타입이니까
- tmp[i]는 char 형입니다.
- tmp + i는 char* 형입니다.

다시 말해 tmp[i] 와 *(tmp+i)가 동일하겠습니다.

tatchi의 이미지

아, 그렇군요. 저런 기본적인 걸 모르다니...
감사합니다:)