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

  FORUM HardWare.fr
  Programmation
  C++

  [c++] 2blemes insides [RESOLU]

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[c++] 2blemes insides [RESOLU]

n°318868
Gandalf_Le​_Gris
Posté le 27-02-2003 à 01:50:57  profilanswer
 

voila je voudrais cacher des commandes ki s executent, je sais ke en batch/basic fo rajouter >nul a la fin, mais en c++ :(
 
pourriez vous m aider, merci d avance


Message édité par Gandalf_Le_Gris le 27-02-2003 à 18:36:45
mood
Publicité
Posté le 27-02-2003 à 01:50:57  profilanswer
 

n°318880
*syl*
--> []
Posté le 27-02-2003 à 08:04:19  profilanswer
 

Quoi ? Qd tu fais un system() par ex ?

n°318915
Gandalf_Le​_Gris
Posté le 27-02-2003 à 09:34:43  profilanswer
 

ui par exemple, enfin je pensais plutot a autre chose, mais ca doit etre pareil ...

n°318945
antp
Super Administrateur
Champion des excuses bidons
Posté le 27-02-2003 à 10:01:03  profilanswer
 

Gandalf_Le_Gris a écrit :

ui par exemple, enfin je pensais plutot a autre chose, mais ca doit etre pareil ...


 
t'emploies quelle fonction ?


---------------
mes programmes ·· les voitures dans les films ·· apprenez à écrire
n°319185
Gandalf_Le​_Gris
Posté le 27-02-2003 à 13:45:45  profilanswer
 

en fait j upload avec ftp en passant par un txt, mais ca m affiche mes mots de pass a l ecran :/

n°319195
western
AJMM
Posté le 27-02-2003 à 13:53:31  profilanswer
 

popen (Attention, j'ignore si cela marche sous Win)

n°319199
Gandalf_Le​_Gris
Posté le 27-02-2003 à 13:56:28  profilanswer
 

ca marche comment ?

n°319202
western
AJMM
Posté le 27-02-2003 à 13:58:57  profilanswer
 

Code :
  1. FILE * fichier = popen("ici ta commande" );
  2. //le fichier fichier va contenir les sorties standard de ta commande
  3. pclose(fichier);

n°319206
Gandalf_Le​_Gris
Posté le 27-02-2003 à 14:03:22  profilanswer
 

bon v essayer, tu pe p-e m aider aussi sur un autre pb, je voulais creer un .txt, mais le nom en random
 

Code :
  1. #define FILE_NAME   "&var.txt" // je sais, ca marche pas ca :p
  2. int var;
  3. srand((unsigned) time(NULL));
  4. var = rand() % 12;


 
mais je c plus comment on fait pour mettre la valeur var en nom du .txt :/

n°319305
*syl*
--> []
Posté le 27-02-2003 à 14:59:22  profilanswer
 

Gandalf_Le_Gris a écrit :

bon v essayer, tu pe p-e m aider aussi sur un autre pb, je voulais creer un .txt, mais le nom en random
 

Code :
  1. #define FILE_NAME   "&var.txt" // je sais, ca marche pas ca :p
  2. int var;
  3. srand((unsigned) time(NULL));
  4. var = rand() % 12;


 
mais je c plus comment on fait pour mettre la valeur var en nom du .txt :/
 

[:meganne]  
 
 
 
 [:ddr555]

mood
Publicité
Posté le 27-02-2003 à 14:59:22  profilanswer
 

n°319308
western
AJMM
Posté le 27-02-2003 à 15:03:15  profilanswer
 

fais une recherche sur le forum: convertir un entier (int) en chaîne de caractères (char *)

n°319358
Gandalf_Le​_Gris
Posté le 27-02-2003 à 15:47:40  profilanswer
 

bah en fait g t un pe a l ouest,
g refait ca:
 

Code :
  1. bool Write_File_Name()
  2.   {
  3.  //random
  4.  srand((unsigned) time(NULL));
  5.  char var = 'a' + ( rand() % 26 );
  6.  cout << "\nLettre au hasard: " << var << endl ;
  7.  return 0;
  8.   }


 
mais alors pour ke le .txt ke je crée s appelle lettre-o-hasard.txt je galere trop trop, vous pouvez m aider ?
 
merci d avance :)

n°319501
Gandalf_Le​_Gris
Posté le 27-02-2003 à 16:29:55  profilanswer
 

:bounce:

n°319563
western
AJMM
Posté le 27-02-2003 à 17:32:04  profilanswer
 

Code :
  1. char * base = "nom";
  2. char * ext = ".txt";
  3. char * nom_au_hasard = new char [(int)strlen(base)+(int)sizeof(int)+(int)strlen(ext)+1];
  4. sprintf("%s%s%s", base, int2chaine(rand()), ext);

n°319598
Gandalf_Le​_Gris
Posté le 27-02-2003 à 17:59:42  profilanswer
 

Code :
  1. char * base = "nom";
  2. char * ext = ".txt";
  3. char * nom_au_hasard = new char [(int)strlen(base)+(int)sizeof(int)+(int)strlen(ext)+1];


 
si je comprends bien, nom_au_hasard = nom.txt ?
 
oki, alors 2 problemes:
'nom_au_hasard' : undeclared identifier je le declare en koi ?
 
donc je mets mon random a la place de "nom", mais si je mets  

Code :
  1. srand((unsigned) time(NULL));
  2. char lettre_au_hasard = 'a' + ( rand() % 26 );
  3. char * base = lettre_au_hasard;
  4. char * ext = ".txt";
  5. char * nom_au_hasard = new char [(int)strlen(base)+(int)sizeof(int)+(int)strlen(ext)+1];


ya une erreur de conversion entre char et char * :/
 
chuis un gros noob mais j aimerais comprendre :(


Message édité par Gandalf_Le_Gris le 27-02-2003 à 18:00:38
n°319607
gloop
Posté le 27-02-2003 à 18:05:00  profilanswer
 

western a écrit :

Code :
  1. char * base = "nom";
  2. char * ext = ".txt";
  3. char * nom_au_hasard = new char [(int)strlen(base)+(int)sizeof(int)+(int)strlen(ext)+1];
  4. sprintf("%s%s%s", base, int2chaine(rand()), ext);




Code :
  1. sprintf(nom_au_hasard, "%s%s%s", base, int2chaine(rand()), ext);


ce serait mieux

n°319609
Gandalf_Le​_Gris
Posté le 27-02-2003 à 18:06:47  profilanswer
 

gloop a écrit :


Code :
  1. sprintf(nom_au_hasard, "%s%s%s", base, int2chaine(rand()), ext);


ce serait mieux


 
ui mais j ai pas besoin de spintf oO

n°319620
Poireau
Posté le 27-02-2003 à 18:18:58  profilanswer
 

Si tu cherche la facilite il existe des fonctions pour creer des fichiers avec des nom aleatoires, des fichiers temporaires :
 
Creates a temporary file.
FILE *tmpfile( void );
Return Value
If successful, tmpfile returns a stream pointer. Otherwise, it returns a NULL pointer.
 
Il y a aussi : _tempnam, _wtempnam, tmpnam, _wtmpnam...
 
Mais si tu veux le faire toi meme je dirai pour le code :

Code :
  1. srand((unsigned) time(NULL));
  2. char * base = "nom";
  3. char * ext = ".txt";
  4. char nom_au_hasard [32] ;
  5. sprintf(nom_au_hasard , "%s%c%s", base, 'a' + rand () % 26, ext);


Message édité par Poireau le 27-02-2003 à 18:20:32
n°319634
Gandalf_Le​_Gris
Posté le 27-02-2003 à 18:36:14  profilanswer
 

decidement, moi ki aimait pas les poireau :D
 
merci !!! (cf mon new post pour mon nvo pb lol)

n°320014
western
AJMM
Posté le 28-02-2003 à 09:38:17  profilanswer
 

gloop a écrit :


Code :
  1. sprintf(nom_au_hasard, "%s%s%s", base, int2chaine(rand()), ext);


ce serait mieux


Ah oui, effectivement, j'ai oublié. Désolé...

n°320018
western
AJMM
Posté le 28-02-2003 à 09:46:16  profilanswer
 

Poireau a écrit :

Si tu cherche la facilite il existe des fonctions pour creer des fichiers avec des nom aleatoires, des fichiers temporaires :
 
Creates a temporary file.
FILE *tmpfile( void );
Return Value
If successful, tmpfile returns a stream pointer. Otherwise, it returns a NULL pointer.
 
Il y a aussi : _tempnam, _wtempnam, tmpnam, _wtmpnam...
 
Mais si tu veux le faire toi meme je dirai pour le code :

Code :
  1. srand((unsigned) time(NULL));
  2. char * base = "nom";
  3. char * ext = ".txt";
  4. char nom_au_hasard [32] ;
  5. sprintf(nom_au_hasard , "%s%c%s", base, 'a' + rand () % 26, ext);




Sert à rien un buffer de 32 octets (après, on dit que les programmes ramment, si pour une broutille comme cela on alloue 32, dans un truc hard, on alloue 100.000 octets, ça rame mieux!)
3 pour la base, 1 pour le caractères hasardeux, 4 pour l'extension, 1 pour le caractère final ('\0';) soit un total de 9 octets ...
Le gain est de 23 octets c'est peu mais dans un programme plus vitale ou plus gourmande, l'accumulation des ces petits gains permet d'augmenter les perfs globales ...  
 
A bon entendeur ...

n°320101
gloop
Posté le 28-02-2003 à 11:30:35  profilanswer
 

Gandalf_Le_Gris a écrit :


Code :
  1. bool Write_File_Name()
  2.   {
  3.  return 0;
  4.   }




en C++, avec des bool, utilise true et false.


Message édité par gloop le 28-02-2003 à 11:31:25
n°320108
gloop
Posté le 28-02-2003 à 11:37:50  profilanswer
 

tant qu'on y est, si t'es en C++:
 

Code :
  1. std::string nomHasard;
  2.    std::ostringstream strStream (nomHasard);
  3.    strStream << "nom" << static_cast <char> ('a' + rand () % 26) << ".txt";


mood
Publicité
Posté le   profilanswer
 


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

  [c++] 2blemes insides [RESOLU]

 

Sujets relatifs
[PHP] session [resolu mais pas comme je veux ;) ]Question sur Tkinter [resolu]
JEditorPane qui s'emmêle ? [RESOLU]Petite question sur import [résolu]
prob d'indentation :( [resolu][Résolu][Php] Problème explorateur de fichiers (lecteur réseau)
problème incroyable.... [RESOLU][Résolu][Php/Oracle] Problème de caractères bizarres après extraction
[Windows] Comment lancer un programme en tache de fond ? RESOLUvariable partagée [C] [résolu]
Plus de sujets relatifs à : [c++] 2blemes insides [RESOLU]


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