Total members 10249 | Gratitudes |It is currently Thu May 17, 2012 8:02 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 2 posts ] 
Author Question
 Question subject: Format Specifier in C
PostPosted: Sat Nov 08, 2008 11:10 pm 
Offline
Proficient
User avatar

Joined: Sun Oct 19, 2008 3:47 pm
Posts: 281
Has thanked: 0 time
Have thanks: 1 time

Hi People,
I have a doubt in C program.
Suppose i have declared int i = 1234;
If I want to print only 12 (first 2 digits) using printf statement, please
suggest how do i implement it.


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: Format Specifier in C
PostPosted: Sat Nov 08, 2008 11:11 pm 
Offline
Proficient
User avatar

Joined: Sun Oct 19, 2008 3:53 pm
Posts: 229
Has thanked: 0 time
Have thanks: 0 time
You can convert the int to a string with sprintf(), then truncate the
string after the first two characters, then display the string.

Alternatively, if you want to achieve a result of 12 mathematically,
you can use modulus (%) and division (/) :

(i - (i % 100)) / 100

== 12


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 2 posts ] 
Quick reply


  

 Similar topics
 database contents display in table format in swing
 Handling m3g format (3D files for mobiles) in J2ME
 i want to draw a circle on a image(any format bmp,jpeg etc.)
 PDF Format
 Number format for current
 Number format function prototype
 Format Debugging Messages

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: Google Adsense [Bot] and 2 guests



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team