Question:
How can I convert a number to a string?
Answer:
refer the library function atoi();
int atoi(char *str); Source: CoolInterview.com
Answered by: Amaresh Das | Date: 11/1/2007
| Contact Amaresh Das
char a[MAX]; while(num !=0) {a[i] = (num%10)+ 30 ;// for ascii value of the digit add 30
num = num/10; i++;
} //a[] contains string format of num with a[0] as MSB in num Source: CoolInterview.com
Answered by: Mubeen | Date: 11/30/2007
| Contact Mubeen
main() { int n;char a[10]; scanf("%d",&n); sprintf(a,"%d",n); printf("%s",a); } //the number will be stored in char array. //you can get this concept in Format specifiers Source: CoolInterview.com
Answered by: samba | Date: 12/28/2007
| Contact samba
char a[MAX]; while(num !=0)
{a[i] = (num%10)+ 30 ;// for ascii value of the digit add 30
num = num/10; i++;
} Source: CoolInterview.com
Answered by: vikram singh | Date: 1/16/2008
| Contact vikram singh
void main() { int n=65; printf("%c",n); } Source: CoolInterview.com
Answered by: baalu | Date: 1/18/2008
| Contact baalu
char a[MAX]; while(num !=0) {a[i] = (num%10)+ 30 ;// for ascii value of the digit add 30
num = num/10; i++;
} //a[] contains string format of num with a[0] as MSB in num
Source: CoolInterview.com
Answered by: dineshkumar | Date: 1/20/2008
| Contact dineshkumar
the previous answer needs to be modified. The line: a[i] = (num%10)+ 30 ; should be: a[i] = (num%10)+ 0x30 ;
the addition should be for hex 0x30 and not decimal 30 to convert to ascii. Source: CoolInterview.com
Answered by: Dammike | Date: 4/10/2008
| Contact Dammike
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|