Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
3009 connectés 

  FORUM HardWare.fr
  Programmation

  [C] une fonction transformant un int en char *

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[C] une fonction transformant un int en char *

n°14627
Titoine42
Posté le 16-02-2001 à 11:45:39  profilanswer
 

en gros je voudrais l'inverse de "atoi"
je suis sûr que ça existe et en plus  ça me soualerait de coder ce genre de fonction
merci d'avance :jap:

mood
Publicité
Posté le 16-02-2001 à 11:45:39  profilanswer
 

n°14636
bipbipbip
Posté le 16-02-2001 à 12:08:13  profilanswer
 

Elle existe essaye itoa je sais plus j'ai pas mon bouquin sous la main mais c'est un truc dans ce genre

n°14637
Toxin
Carpe ★★ Vitam
Posté le 16-02-2001 à 12:13:36  profilanswer
 

Ben je crois que ça n'existe pas en fait. En tout cas pas sous SOLARIS.


---------------
"If you can walk away from a landing, it's a good landing. If you use the airplane the next day, it's an outstanding landing." - Chuck Yeager. | Ma chaîne YT
n°14638
Titoine42
Posté le 16-02-2001 à 12:15:54  profilanswer
 

g déjà testé itoa mais ça n'existe po

n°14642
Titoine42
Posté le 16-02-2001 à 13:00:51  profilanswer
 

:cry:

n°14643
gilou2
Posté le 16-02-2001 à 13:11:01  profilanswer
 

char chaine[256];
int entier;
 
sprintf(chaine, "%d", entier);


---------------
Développeur de FreeVCR : http://freevcr.ifrance.com [:gilou2]
n°14644
Toxin
Carpe ★★ Vitam
Posté le 16-02-2001 à 13:14:06  profilanswer
 

Raaaah vi les solutions les plus simples sont les meilleures. Putain je suis con des fois.


---------------
"If you can walk away from a landing, it's a good landing. If you use the airplane the next day, it's an outstanding landing." - Chuck Yeager. | Ma chaîne YT
n°14646
Titoine42
Posté le 16-02-2001 à 13:27:28  profilanswer
 

c klair j'suis trop con, j'aurais du y penser
 
merci beaucoup :jap:

n°14666
golgoth99
Posté le 16-02-2001 à 16:21:58  profilanswer
 

Petite precision quand meme la fonction convertissant en char* existe : _itoa(int,char*,base);

n°14669
verdoux
And I'm still waiting
Posté le 16-02-2001 à 16:30:20  profilanswer
 

Et c'est dans quel include ?

mood
Publicité
Posté le 16-02-2001 à 16:30:20  profilanswer
 

n°14671
golgoth99
Posté le 16-02-2001 à 16:37:08  profilanswer
 

Alors la question piege, dans la stdlib, je crois mais sans aucune certitude

n°14676
WiseTechi
Posté le 16-02-2001 à 17:25:58  profilanswer
 

Oui, c'est bien ça (dans stdlib.h) :
char *_itoa( int value, char *string, int radix );
value
  Number to be converted
string
  String result
radix
  Base of value; must be in the range 2 – 36
 
A++

n°14677
verdoux
And I'm still waiting
Posté le 16-02-2001 à 17:32:41  profilanswer
 

Moi je l'ai pas dans stdlib.h (sous linux).

n°14679
zop
1 world, 1 web, 1 Windows
Posté le 16-02-2001 à 17:49:15  profilanswer
 

C'est une fonction Microsoft _itoa

n°14683
slaanesh
Rebellz ken tu nous tiens....
Posté le 16-02-2001 à 18:06:07  profilanswer
 

le mieux vu k'elle existe pas ss ttes les archi, c de coder sa propre fonction :
 
int get_nb_chiffre(int nbr)
{
  int result;
 
  result = 0;
  if (!nbr)
    return (1);
  else
    {
      while (nbr)
 {
   nbr %= 10;
   result++;
 }
      return (result);
    }
}
 
char *int_to_str(int nbr)
{
  char *buff;
  char *result;
 
  result = buff = malloc(get_nb_chiffre(nbr) + 1);
  while (nbr)
    {
      *buff++ = '0' + nbr / 10;
      nbr %= 10;
      if (!nbr)
 *buff = '0';
    }
  *buff = 0;
  return (result);
}


---------------
Ne remets pas à demain ce que tu peux faire après-demain ! :sol:
n°14696
Titoine42
Posté le 16-02-2001 à 19:01:04  profilanswer
 

:jap:  :jap:  :jap:

n°14697
slaanesh
Rebellz ken tu nous tiens....
Posté le 16-02-2001 à 19:10:30  profilanswer
 

:)


---------------
Ne remets pas à demain ce que tu peux faire après-demain ! :sol:
n°14711
gilou
Modérateur
Modzilla
Posté le 16-02-2001 à 23:13:50  profilanswer
 

gilou2 a écrit a écrit :

char chaine[256];
int entier;
 
sprintf(chaine, "%d", entier);




 
Oui, ca c'est la pratique standard des codeurs C.
A+,


---------------
There's more than what can be linked! --    Iyashikei Anime Forever!    --  AngularJS c'est un framework d'engulé!  --
n°14784
MilesTeg
Posté le 17-02-2001 à 20:58:03  profilanswer
 

Je confirme, ça fait 10 ans que je travaille en C sous UNIX et sprintf est ce qu'il y a de plus simple et de plus portable.
 
@+


---------------
---------------------------------------------

Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation

  [C] une fonction transformant un int en char *

 

Sujets relatifs
[VC] BSTR to charErreur fonction PHP strpos
PHP Fonction Mail... Config ??Problème sur une fonction C++ de base...
[php] il faut un .dll en plus pour la fonction crypt() ?java: fonction eval()
du php dans une fonction javascript ?[C] C koi la fonction pour exécuter un programme ?
API - Est il possible de définir un temps d'execution d'une fonction 
Plus de sujets relatifs à : [C] une fonction transformant un int en char *


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR