fontion itoc [c , c++] - Programmation
Marsh Posté le 28-12-2001 à 20:35:27
itoc n'existe pas à ma connaissance, il existe itoa qui convertit un int en ça représantatino dans une base quelconque sous forme de chaine de charactaire, par exemple:
char chaine[11];
int i=10;
itoa(i,chaine,10); /*vérifier l'ordre des paramettre je n'en suis pas sur*/
printf("%s",chaine);
le résultat à l'écran est: 10
itoa doit être dnas stdlib.h normalement
Marsh Posté le 28-12-2001 à 23:35:28
heuuu marche pas :=(((
j'ai le droit comme avec itoc a un jolie undefined reference to itoa :=(((((
si quelqu'un avait la solution pour transformer mon int en char (meme sans itoc ou itoa je m'enfou)
merci d'avance et ++
[edtdd]--Message édité par bilbobman--[/edtdd]
Marsh Posté le 28-12-2001 à 23:48:15
int en char ? int en char * plustôt non ?
sinon :
int i;
char c;
i = 5;
c = i + '0'; // c = '5' marche pour tout i < 10
sinon pour les entiers + grand que 10 y a moyen je crois avec sscanf ou sprintf.... à regarder...
Marsh Posté le 29-12-2001 à 00:39:35
_itoa, _i64toa, _ui64toa, _itow, _i64tow, _ui64tow
Convert an integer to a string.
char *_itoa( int value, char *string, int radix );
char *_i64toa( __int64 value, char *string, int radix );
char * _ui64toa( unsigned _int64 value, char *string, int radix );
wchar_t * _itow( int value, wchar_t *string, int radix );
wchar_t * _i64tow( __int64 value, wchar_t *string, int radix );
wchar_t * _ui64tow( unsigned __int64 value, wchar_t *string, int radix );
Routine Required Header Compatibility
_itoa <stdlib.h> Win 95, Win NT
_i64toa <stdlib.h> Win 95, Win NT
_ui64toa <stdlib.h> Win 95, Win NT
_itow <stdlib.h> Win 95, Win NT
_i64tow <stdlib.h> Win 95, Win NT
_ui64tow <stdlib.h> Win 95, Win NT
For additional compatibility information, see Compatibility in the Introduction.
Libraries
LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version
Return Value
Each of these functions returns a pointer to string. There is no error return.
Parameters
value
Number to be converted
string
String result
radix
Base of value; must be in the range 2 ? 36
Remarks
The _itoa, _i64toa, and _ui64toa function convert the digits of the given value argument to a null-terminated character string and stores the result (up to 33 bytes) in string. If radix equals 10 and value is negative, the first character of the stored string is the minus sign ( ? ). _itow, _i64tow, and _ui64tow are wide-character versions of _itoa, _i64toa, and _ui64toa respectively.
Generic-Text Routine Mappings
TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_itot _itoa _itoa _itow
Example
/* ITOA.C: This program converts integers of various
* sizes to strings in various radixes.
*/
#include <stdlib.h>
#include <stdio.h>
void main( void )
{
char buffer[20];
int i = 3445;
long l = -344115L;
unsigned long ul = 1234567890UL;
_itoa( i, buffer, 10 );
printf( "String of integer %d (radix 10): %s\n", i, buffer );
_itoa( i, buffer, 16 );
printf( "String of integer %d (radix 16): 0x%s\n", i, buffer );
_itoa( i, buffer, 2 );
printf( "String of integer %d (radix 2): %s\n", i, buffer );
_ltoa( l, buffer, 16 );
printf( "String of long int %ld (radix 16): 0x%s\n", l,
buffer );
_ultoa( ul, buffer, 16 );
printf( "String of unsigned long %lu (radix 16): 0x%s\n", ul,
buffer );
}
Output
String of integer 3445 (radix 10): 3445
String of integer 3445 (radix 16): 0xd75
String of integer 3445 (radix 2): 110101110101
String of long int -344115 (radix 16): 0xfffabfcd
String of unsigned long 1234567890 (radix 16): 0x499602d2
Data Conversion Routines
See Also _ltoa, _ultoa
Marsh Posté le 29-12-2001 à 01:36:42
sinon y a sprintf, ça permet de choisir le formatage du nombre (zéros, etc...)
c'est bizarre ce _ devant itoa. Y a que dans VC++ que j'ai vu ça, dans les autres compilateurs c'était simplement itoa.
Marsh Posté le 29-12-2001 à 01:54:21
antp a écrit a écrit : sinon y a sprintf, ça permet de choisir le formatage du nombre (zéros, etc...) c'est bizarre ce _ devant itoa. Y a que dans VC++ que j'ai vu ça, dans les autres compilateurs c'était simplement itoa. |
Il me semble que itoa n'est pas compatible linux....
Mais sprintf marche....
Marsh Posté le 29-12-2001 à 11:53:25
Ah je m'excuse bien, itoa je l'utilise sous Linux et ca va bien merci. Mais la effectivement ton probleme est bizarre et sprintf est la solution la plus simple.
Marsh Posté le 29-12-2001 à 11:59:46
oki , je vous remercie , je test tout de suite avec sprintf ( je connais pas encore mais je cherche de la doc ca ira :=) )
heuuu , sinon gousy , j'ai aussi la MSDN :=)
merci encore je teste ca tout de suite
Marsh Posté le 29-12-2001 à 12:00:18
R3g a écrit a écrit : Ah je m'excuse bien, itoa je l'utilise sous Linux et ca va bien merci. Mais la effectivement ton probleme est bizarre et sprintf est la solution la plus simple. |
La dernière fois que G essayé itoa sous linux (avec gcc) je me suis fait jetter
Mais bon c'était en cours et G pas trop cherché... G utilisé sprintf....
Marsh Posté le 29-12-2001 à 12:16:20
rhooo , je vous adore les gars , ca marche niquel :=)) je connaiser pas cette fonction , honte a moi :=)
merci encore pour vos reponce rapide :=)
heu sinon moi aussi j'utilise GCC , c louche , a l'ocasion je vais tester ca avec un autre compilateur ...
enfin ca marche , je suis content merci encore
++
Marsh Posté le 29-12-2001 à 23:24:24
bilbobman a écrit a écrit : rhooo , je vous adore les gars , ca marche niquel :=)) je connaiser pas cette fonction , honte a moi :=) merci encore pour vos reponce rapide :=) heu sinon moi aussi j'utilise GCC , c louche , a l'ocasion je vais tester ca avec un autre compilateur ... enfin ca marche , je suis content merci encore ++ |
Pas la peine Gcc est un des meilleurs compilo du marché
Marsh Posté le 28-12-2001 à 19:30:12
voila , je cherche a convertir un int en char , la fonction itoc permet de le faire en theorie , le probleme c que je ne c pas quelle header inclure pour que ca marche , a chaque fois ca couille ( en gros y trouve pas la fonction ) je precise je suis sous linux , je c pas si ca a une influance , si quelqu'un pouvait m'aider en me donnant le nom du header , j'ai deja essayer les principaux : stdio.h , string.h strings.h ect ...
voila merci d'avance ++