Hello ,,,

Please I need Your Help as soon As Possible..

I have an array of integers and i need to convert it to string ...


PlZ Help me as soon as Possible ...

i have do a dynamic array of integers and i store the values.

for(int i=Count-1 ; i>=0 ; i--)
    {
    Digit[i]=(str[i]-'0');
    }

this is my code first i convert string to array then i need to convert it back to string after doing some operations >>>

plz help

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Hello charming--eyes,
Do you want a string like "7456" if the integer array a[5] has a[0]=7,a[1]=4,a[2]=5,a[4]=6 ?

Edited 5 Years Ago by Arbus: n/a

std::stringstream out;
    for(size_t i=0; i < size; i++)
    {
        int x = digit[i];
        x = x >> i; // do something to digit
        out << x;
    }

Edited 5 Years Ago by template<>: n/a

Hello charming--eyes,
The ASCII value of numeric characters start from 48 which refers to 0.Add the integer and 48,then store it in the character array.

int a[100];
char a[100];
a[0]=48+f[0];

For example if f[0] has 7,then 48 +7 = 55.So a[0] will take up the ASCII value as 55.
Put this in a loop. You will have the integers converted to string.

Edited 5 Years Ago by Arbus: n/a

Comments
Thanks

How is that your code? That's a reference link to strcat.

Err, I'm not the OP... I was trying to help him by pointing him to a method of combining strings.

**Basic Code in C Language**


#include<stdio.h>
#include<malloc.h>
void int_to_char_array(int *arr,int arrLen,char *str)
{
    int count=0;
    while(count<arrLen)
    {
        if(*(arr+count)/10!=0)
        {
            *str++=*(arr+count)/10+'0';
            *(arr+count)%=10;
        }
        else
        {
            *str++=*(arr+count)%10+'0';
            count++;
        }
    }
    *str='\0';
}

void main()
{
    int *arr,arrLen,count;
    char *str;
    puts("Enter size of int array :");
    scanf("%d",&arrLen);
    arr=(int *)malloc(sizeof(int)*arrLen);
    str=(char *)malloc(sizeof(char)*arrLen);
    puts("Enter elements of int array :");
    for(count=0;count<arrLen;count++)
        scanf("%d",(arr+count));
    int_to_char_array(arr,arrLen,str);
    puts("Main Result :");
    puts(str);
}
This article has been dead for over six months. Start a new discussion instead.