NameSilo

[Resolved] C: Integer to String.

Spaceship Spaceship
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
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
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
•••

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back