Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

C18 sprintf

Status
Not open for further replies.

AtomSoft

Well-Known Member
Hey guys just want to ask what could be a simple question. Im using sprintf to output numbers into string format which is working well.

But i would like 2 characters. Like when i have a char and the number is anywhere from 0 to 9 i get 0 to 9 but i would like to get 00-09.. get it?

I usually get:
0
1
2
3
4
5
6
7
8
9
10 - FIRST 2 CHARACTERS

I would like:

00
01
02
03
04
05
06
07
08
09
10

Is it possible to some how force this in sprintf? or should i simply:

Code:
			if(Data< 10){
				sprintf(Data2,"0%d\0",Data);
			} else {
				sprintf(Data2,"%d\0",Data);
			}
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top