<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<atom:link href="http://forum.ubuntu-fr.org/extern.php?action=feed&amp;tid=21953&amp;type=rss" rel="self" type="application/rss+xml" />
		<title><![CDATA[Forum Ubuntu-fr.org / Fonction itoa (conversion de type)]]></title>
		<link>http://forum.ubuntu-fr.org/viewtopic.php?id=21953</link>
		<description><![CDATA[Les sujets les plus récents dans Fonction itoa (conversion de type).]]></description>
		<lastBuildDate>Wed, 21 Dec 2005 17:52:53 +0000</lastBuildDate>
		<generator>FluxBB</generator>
		<item>
			<title><![CDATA[Réponse à&#160;:  Fonction itoa (conversion de type)]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=152137#p152137</link>
			<description><![CDATA[<div class="quotebox"><cite>Kiboumz a écrit&#160;:</cite><blockquote><div><p>Bonjour,</p><p>y&#039;a t-il une raison en particulier pourquoi cette fonction n&#039;est pas disponible, je trouve cela un peu dommage et j&#039;espère que cela n&#039;arrive pas trop souvent...</p><p>merci<br />a+</p></div></blockquote></div><p>En fait, elle n&#039;existe pas pour une raison toute simple : il faut utiliser la fonction <strong>snprintf()</strong> qui se comporte comme <strong>printf()</strong> sauf que le résultat est stocké dans une chaîne de caractères.</p><p>Bref, le code qui réalise ce que tu veux faire est :</p><div class="codebox"><pre><code>// ...
#define LENGTH 256
int a = -512;
char res[LENGTH];
// initialisation de res[]
snprintf(res, LENGTH, &quot;%i&quot;, a);</code></pre></div><p>Et le tour est joué <img src="http://forum.ubuntu-fr.org/img/smilies/smile.png" width="15" height="15" alt="smile" /></p><p>Cela offre un avantage certain : une fonction suffit pour tous les types pouvant être formattés par la famille des <strong>printf()</strong>. <br />Eofr&gt; désolé ... <img src="http://forum.ubuntu-fr.org/img/smilies/smile.png" width="15" height="15" alt="smile" /></p>]]></description>
			<author><![CDATA[dummy@example.com (thx1138)]]></author>
			<pubDate>Wed, 21 Dec 2005 17:52:53 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=152137#p152137</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  Fonction itoa (conversion de type)]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=152039#p152039</link>
			<description><![CDATA[<p>Bonjour,</p><p>y&#039;a t-il une raison en particulier pourquoi cette fonction n&#039;est pas disponible, je trouve cela un peu dommage et j&#039;espère que cela n&#039;arrive pas trop souvent...</p><p>merci<br />a+</p>]]></description>
			<author><![CDATA[dummy@example.com (Kiboumz)]]></author>
			<pubDate>Wed, 21 Dec 2005 15:49:09 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=152039#p152039</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  Fonction itoa (conversion de type)]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=151679#p151679</link>
			<description><![CDATA[<p>itoa() n&#039;est pas disponible sous Linux. Voilà le code pour des entiers positifs</p><div class="codebox"><pre class="vscroll"><code>#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
#include &lt;math.h&gt;

int
long_int (int n)
{
	float x = log10 (n);
	return (int) x + 1;
}

char *
retourne (char *a)
{
	char *b = malloc (strlen (a));
	int i;
	for (i = 0; i &lt; strlen (a); i++)
	{
		b[i] = a[strlen (a) - i - 1];
	}
	b[i] = &#039;\0&#039;;
	return b;

}


char *
itoa (int n)
{

	char *a = malloc (long_int (n) + 1);
	int i;
	for (i = 0; n &gt; 0; i++)
	{
		a[i] = n % 10 + 48;
		n = n / 10;
	}
	a[i + 1] = &#039;\0&#039;;
	return retourne (a);

}</code></pre></div><p>Je te laisse le soin d&#039;adapter au cas où l&#039;entier est negatif</p>]]></description>
			<author><![CDATA[dummy@example.com (eofr)]]></author>
			<pubDate>Wed, 21 Dec 2005 10:02:30 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=151679#p151679</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  Fonction itoa (conversion de type)]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=151632#p151632</link>
			<description><![CDATA[<p>L&#039;en-tête <strong>stdlib.h</strong> n&#039;est pas unique à Windows. Si je ne dis pas de bêtise, il fait partie de la bibliothèque standard du C et est donc disponible sur toutes les plateformes qui offrent une telle bibliothèque.</p><p>La fonction <strong>itoa()</strong> n&#039;est, quant à elle, pas dans la bibliothèque standard.</p><p>PS : ces infos sont à prendre avec précaution, je n&#039;ai pas eu le temps de vérifier.</p>]]></description>
			<author><![CDATA[dummy@example.com (thx1138)]]></author>
			<pubDate>Wed, 21 Dec 2005 08:31:36 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=151632#p151632</guid>
		</item>
		<item>
			<title><![CDATA[Fonction itoa (conversion de type)]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=151558#p151558</link>
			<description><![CDATA[<p>Bonjour, j&#039;essaie de compiler un programme utilisant la fonction <strong>itoa</strong> (de la librairie stdlib.h), mais ça me dit une erreur comme quoi la fonction <strong>itoa </strong> (conversion d&#039;un int en char) n&#039;existe pas. Pourtant, je peux utiliser la fonction atoi (conversion d&#039;un char en int), mais moi j&#039;ai besoin de <strong>itoa</strong> et non d&#039;atoi, alors je ne comprends pas comment pouvoir utiliser cette fonction qui marche pourtant très bien quand je compile avec visual studio sous windows, mais avec gcc cela ne fonctionne pas... la librairie stdlib est-elle unique à windows... ? et existe t&#039;il une fonction similaire à <strong>itoa</strong> ?</p><p>merci<br />a+</p>]]></description>
			<author><![CDATA[dummy@example.com (Kiboumz)]]></author>
			<pubDate>Tue, 20 Dec 2005 23:56:35 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=151558#p151558</guid>
		</item>
	</channel>
</rss>
