NameSilo

[Resolved] C: Integer to String.

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
Watch

Barrucadu

Established Member
Impact
64
C: Integer to String.

I'm (attempting) to make a very basic operating system, and am stuck.
Code:
     puts("Current System Ticks: ");
     putl(timer_ticks);

puts() displays a string on the screen, putl() does the same thing, but with a '\n' at the end of the string.
The problem is that timer_ticks is an integer. So basicly it prints something like "Current System Ticks: =E<".

I need a function to convert intergers to strings, but the function needs to be written from scratch. Not using anything from an include file.

A function to convert back from string to integer would also be good :)
 
Last edited:
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Resolved. I found the code for a custom itoa() function:

Code:
char* itoa(int n, char *buff, int radix){
	int q, r;
	int i = 0;
	char tmp[33];
	do{
		q = n / radix;
		r = n % radix;
		n = q;
		tmp[i++] = 48 + r;
	}while(q > 0);
	int j;
	for(j = 0; j < i; j++){
		buff[j] = tmp[i - j - 1];
	}
	buff[j] = '\0';
	return buff;
}
 
0
Close
DomainEasy: white label portfolios are live. Enable yours.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back