conversion of Int to Char
-
Actually, am having an array of Int values, i would like to convert into char array, as i need to save this data in a text file. am using itoa(), but i couldne get the result. Can anybody could help me out?
-
Actually, am having an array of Int values, i would like to convert into char array, as i need to save this data in a text file. am using itoa(), but i couldne get the result. Can anybody could help me out?
I suppose you want to convert int values into strings (and not into a char value). What is the problem with itoa ? You could also use sprintf.
-
Actually, am having an array of Int values, i would like to convert into char array, as i need to save this data in a text file. am using itoa(), but i couldne get the result. Can anybody could help me out?
Hi chaitanya22, For save data in the file please studing CArchive
-
Actually, am having an array of Int values, i would like to convert into char array, as i need to save this data in a text file. am using itoa(), but i couldne get the result. Can anybody could help me out?
You cannot convert the entire array at once using
itoa
. You have to pick out individual elements for conversion. For eg:#include "stdafx.h"
#include "sstream"int main()
{
string strIntArray;
stringstream sstr;
int randomArray[10];//fill this array with random elements.... for(int index=0;index<10;index++) { randomArray\[index\] = rand()%10000; } //convert each element... for(int index=0;index<10;index++) { sstr<
Nibu thomas
Software Developer -
Actually, am having an array of Int values, i would like to convert into char array, as i need to save this data in a text file. am using itoa(), but i couldne get the result. Can anybody could help me out?
hi, did u include stdlib.h where itoa() is described? Chetan. Helping others satisfies you...
-
I suppose you want to convert int values into strings (and not into a char value). What is the problem with itoa ? You could also use sprintf.
actually, i would like to load the int array data which is obtained from a machine to a txt file, i could open the text file, but i couldnt write the data i,e int array to text file, its writing some junk values. int array[100];//am having an int array char txt[100];//would like to convert the numbers in int array to string and should be stored in txt array. for(i=0;i<=100;i++) {itoa(array[i],txt,10); fwrite(txt,1,strlen(txt),f);//f=fopen("data.txt", "w+"); }
-
hi, did u include stdlib.h where itoa() is described? Chetan. Helping others satisfies you...
ya, i have included
-
Actually, am having an array of Int values, i would like to convert into char array, as i need to save this data in a text file. am using itoa(), but i couldne get the result. Can anybody could help me out?
chaitanya22 wrote:
Actually, am having an array of Int values, i would like to convert into char array, as i need to save this data in a text file.
There is no need to convert just to save to a text file. Numbers can be written to the file just like characters can.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
-
ya, i have included
Hi Chaitanya, Try out this. FILE *fp; fp = fopen("chat.txt","w"); int a[10] = {5,15,25,35,45,55,65,75,85,95}; char p[20]; for (int i = 0;i < 10; i++) { itoa(a[i],p,10); fprintf(fp,"%s ",p); } Chetan. Helping others satisfies you...