SkYlEsS
Elite
C'est quoi comme type de code ça ? :-'
void Parse(const string & Path, const string & Attribute) {
string Buffer;
bool Comment = false;
int FoundElements = 0;
int LastPos = 0;
int Pos = 0;
int Pos2 = 0;
string Key;
//Decoupe du Path en un tableau de string
//Compter le nombre de "/"
int PathTabSize = 0;
for (int Index = 0; Index < Path.size(); Index++) {
if (Path[Index] == '/')
PathTabSize++;
}
string PathTab[PathTabSize];
while (1) {
//PathTab[FoundElements] = Path.substr(LastPos, LastPos = );
//cout << PathTab[FoundElements] << endl;
Pos = Path.find("/", LastPos);
Buffer = Path.substr(LastPos, Pos - LastPos);
if (Buffer.size()) {
PathTab[FoundElements] = Buffer;
FoundElements++;
}
if (Pos == string::npos)
break;
LastPos = ++Pos;
}
FoundElements = 0;
//Ouverture du fichier
ifstream Fichier("./Wiimote_Config.xml", ios::in);
//On lit chaque ligne
while (!Fichier.eof()) {
getline(Fichier, Buffer);
//Netoyage
while (1) {
Pos = Buffer.find("\x09", 0);
if (Pos != string::npos)
Buffer.erase(Pos, 1);
else
break;
}
//Si la ligne contient "<!--" on active le mode commentaire
if (Buffer.find("<!--") != string::npos)
Comment = true;
if (!Comment) {
//Extraction du nom de la cle
Key = Buffer.substr(1, (Pos = Buffer.find_first_of(' '))- 1);
if (Pos == string::npos)
Key = Buffer.substr(1, Buffer.find_first_of(">") - 1);
//cout << Key << endl;
if (Key == PathTab[FoundElements] && Key[0] != '/') {
//cout << Buffer << endl;
FoundElements++;
if (FoundElements == PathTabSize) {
//cout << Buffer << endl;
//Extraction de la valeur si Attribute = NULL
if (!Attribute.size()) {
Pos = Buffer.find_first_of('>') + 1;
Pos2 = Buffer.find_first_of('<', Pos);
cout << Buffer.substr(Pos, Pos2 - Pos) << endl;
}
else {
Pos = Buffer.find(Attribute);
Pos2 = Buffer.find_first_of(' ', Pos);
if (Pos2 == string::npos)
Pos2 = Buffer.find_first_of('>', Pos);
Pos += Attribute.size() + 2;
Pos2 -= 1;
cout << Buffer.substr(Pos, Pos2 - Pos) << endl;
}
}
}
}
//Si la ligne contient "-->" on désactive le mode commentaire
if (Buffer.find("-->") != string::npos)
Comment = false;
}
Fichier.close();
}
neku a dit:Afficher sous forme hexa une zone mémoire
Et après on se demande à quoi sert printf()...Code:if ((int)*(Pointer + i) < 0x10) \ cout << hex << "0x0" << (int)*(Pointer + i) << " "; \ else \ cout << "0x" << hex << (int)*(Pointer + i) << " "; \
Ceci dit c'est le genre de fonction de debug qui a plus intérêt à être dans un outil externe que dans le programme débuggué.Code:/** * Don't use void* since sizeof(void) is not supposed to be defined * (see C99 section 6.2.5 § 1 and 19). */ void hexdump(FILE *out, unsigned char *ptr, size_t len) { static const size_t bytes_per_line = sizeof(int)*2; assert(out != NULL && ptr != NULL && ptr + len > ptr); for (size_t i = 0; i < len; i++) { if (i % bytes_per_line == 0) fprintf(out, "%p: ", (void*)&ptr[i]); fprintf(out, "%02x", (unsigned int)ptr[i]); fprintf(out, "%c", (i + 1) % bytes_per_line ? ' ' : '\n'); } if (len % bytes_per_line != 0) fprintf(out, "\n"); }
#include <termios>
#include <unistd>
//Reviens en mode ascii
#define toascii() printf("\017");
//Active le mode permettant l'affichage de caractère spéciaux
#define tospecial() printf("\033)0\016");
//Idem gotoxy(x,y) Borland
void gotoxy(int x, int y) {
printf("\033[%d;%dH", y, x);
}
//Idem clrscr() Borland
void clrscr() {
printf("\033[1;1H");
printf("\033[2J");
}
//Idem getch() Borland
int getch() {
struct termios oldt, newt;
int ch;
tcgetattr(STDIN_FILENO, &oldt);
newt = oldt;
newt.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
ch = getchar();
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
return ch;
}
$array[] = 'un' ;
$array[] = 'deux' ;
Array( [0] => 'un' , [1] => 'deux' );
Personnellement je préfère faire :Ahava a dit:En fait je reviens sur mon "astuce" en PHP là :
Cela donne :Code:$array[] = 'un' ; $array[] = 'deux' ;
Pas besoin d'utiliser une fonction pour rien quoi.Code:Array( [0] => 'un' , [1] => 'deux' );
ob_start("ob_gzhandler");