Retourner au contenu associé (entrée de forum : Probleme de memoire, sprintf)
Posté par abgech le 13 août 2005 à 10:12. En réponse au message Probleme de memoire, sprintf. Évalué à 1.
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
# Une solution
Posté par abgech . En réponse au message Probleme de memoire, sprintf. Évalué à 1.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
extern char* getipaddress(const char *) ;
int main()~
{
char * myip;
char * mystring;
char cal_long[2]; // CHAINE BIDON POUR DETERMINER LA LONGUEUR A ECRIRE
int longueur; // CONTIENT LA LONGUEUR DE LA CHAINE A ECRIRE
myip = getipaddress("eth0");
longueur = snprintf(mystring,sizeof(cal_long),"mon adresse ip est :%s",myip); // CALCUL DE LA LONGUEUR
if ((mystring = malloc(longueur)) == NULL)
{printf("ERREUR ALLOCATION MEMOIRE\n");
exit(1);
}
sprintf(mystring,"mon adresse ip est :%s",myip);
// printf("ici mon string : %s",mystring);
free(mystring);
return(1);
}