CoolInterview.com - World's Largest Collection of Interview Questions
Send Free SMS
 Interview Questions  
 Our Services  


INTERVIEW QUESTIONS LANGUAGES C DETAILS
Question :
How can I convert a number to a string?



Category C Interview Questions
Rating (4.1) By 15 users
Added on 7/19/2006
Views 3211
Rate it!
Answers:

We can convert number to string using built in function itoa().




we can convert number to string using sprintf() function as shown below.

char result[100];
int num = 24;
sprintf( result,"%d",num);



 Posted by: Ravikumar M    

Contact Ravikumar M  Contact Ravikumar M

even if we use printf with %s,the no is interpretted 4 string



 Posted by: varun    

Contact varun  Contact varun

#include<stdlib.h>
void main()
{
char s[10];
int a=4521;
itoa(a,s,10);
printf("%s",s);
}



 Posted by: juned khan    

Contact juned khan  Contact juned khan

#include <stdio.h>

int main(void)
{
const char base[] = "filename";
char filename [ FILENAME_MAX ];
int number = 42;
sprintf(filename, "%s%d", base, number);
printf("filename = "%s" ", filename);
return 0;
}

/* my output
filename = "filename42"
*/#include <stdio.h>

int main(void)
{
const char base[] = "filename";
char filename [ FILENAME_MAX ];
int number = 42;
sprintf(filename, "%s%d", base, number);
printf("filename = "%s" ", filename);
return 0;
}

/* my output
filename = "filename42"
*/



 Posted by: santosh kumar mallick    

Contact santosh kumar mallick  Contact santosh kumar mallick


If you have the better answer, then send it to us. We will display your answer after the approval.
Name :*
Email Id :*
Answer :*
Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
Process Verification  Enter the above shown code:*
Inform me about updated answers to this question

   
Related Questions
View Answer
What is the difference between #include <file> and #include ?file??


View Answer
What is Preprocessor?


View Answer
What is the difference between text and binary modes?


View Answer
What is the benefit of using const for declaring constants?


View Answer
What is the difference between declaring a variable and defining a variable?


View Answer
What is a const pointer?
View Answer
What is an lvalue?


View Answer
When is a switch statement better than multiple if statements?


View Answer
Can static variables be declared in a header file?


View Answer
Difference between Funtion to pointer and pointer to function

View Answer

Please Note: We keep on updating better answers to this site. Subscribe to our newsletter to get notified when better answer is posted.

Notify me when better answer is posted!
Email:

View ALL C Interview Questions

User Options
Sponsored Links


Copyright ©2003-2010 CoolInterview.com, All Rights Reserved.
Privacy Policy | Terms and Conditions
Page URL: http://www.coolinterview.com/interview/6063/default.asp?cachecommand=bypass


Download Yahoo Messenger | Placement Papers| FREE SMS | ASP .Net Tutorial | Web Hosting | Free SMS | Dedicated Servers | Joke of the Day

0.92