Conversion error from int to String

0

This code I'm using to study C, is not converting (at least eh what I think) to INT temp10 to CHAR ... with an error appearing:

line 5: 5182 Targeting failure (recorded core image)

What can it be?

int main() {
    // aqui esta tudo OK!
    char tempA[100] = "11";
    printf("COUVE = %s\n", tempA);

    strcpy(tempA, "22");
    printf("CEREJA = %s\n", tempA);

    strcpy(tempA, "kk");
    outraFuncao(tempA);

    //  mas se transformo um int em string:
    temp6 = 1000;
    temp7 =  100;
    temp8 =   10;
    temp9 =    1;
    temp10= temp6+temp7+temp8+temp9;
    char temp10=temp10+'0';

    printf("\n\n\n");
    //  da falha de segmentacao na hora do print
    printf("CEREJA2 = %s\n", temp10);

    //  aqui vai ser importante para meu programa... chamar um funcao com esse valor convertido de int para char
    //  mas o mesmo erro defalha desegmentacao acontece..
    outraFuncao(temp10);
} 


void outraFuncao(char *temp) {
    //  strcpy(temp, "33");
    printf("AMORA = %s\n", temp);
}
    
asked by anonymous 17.09.2016 / 03:02

1 answer

1

NOT is a int transformed into a string, is converting a int to A character ... it just does not make sense

 temp10= temp6+temp7+temp8+temp9;
 char temp10=temp10+'0';

 printf("\n\n\n");
 //  da falha de segmentacao na hora do print
 printf("CEREJA2 = %s\n", temp10);

One way to turn an int into a temp10 is with the function string

char buf[20];
snprintf(buf, 20, "CEREJA=%d\n", temp10);

But in your example you do not even need it, you can just do it

printf("CEREJA=%d\n", temp10);
17.09.2016 / 03:17