2013-02-24 6 views
0

내가그것은 내 게시물 문자열 정수에 가입하는 것입니다,

void function(int x){ 
    char* response="GET /postTEST.php?first="; 

    char strx[2] = {0}; 
    int num = x; 
    sprintf(strx, "%d", num); 

    original=response; 
    strcat(response,strx); 
    Serial.println(response); 
    //memset(response,'\0',80); 
} 

기본적으로 아두 이노에서이 코드를 세척하지 strcat와. 불행히도, 어떻게 든 성장하고 어떻게 든된다. GET /postTEST.php?first=0 GET /postTEST.php?first=01 GET /postTEST.php?first=012 나는 i를 늘린다.

어째서?

+0

가 전달 된 정수 한 자리인가 :

는 또한 불필요한 단계는,이 같은 제안합니까? 그것은'strx [2] '를 사용하여 공간을 할당 한 것입니다. –

답변

3

문자열 리터럴을 수정할 수 없습니다. 문자열 리터럴은 상수입니다.

숫자를 추가 할 수있는 충분한 공간이있는 배열로 선언해야합니다.

void function(int x) 
{ 
    char response[64]; 

    sprintf(response, "GET /postTEST.php?first=%d", x); 

    Serial.println(response); 
}