Hilfe kann Hex Werte nicht auslesen!!



  • Hallo ich habe noch ein Problem, ich kann folg. Dateien nicht öffnen:

    log1-041a.07
    log1-041b.07
    log1-041c.07
    log1-041d.07
    log1-041e.07

    Ich versuche die Dateien mit dieser Funktion zu öffnen:

    for (int i = 0x1A ; i< 0x1F; i++)
      for (int j = 0x00; j<0x0A; j++)
    
      { 
      ifstream in; 
    
      sprintf(szDateiPfad,"%slog1-04%d.0%d",temp.c_str(),i,j);
      printf("OEFFNE DATEI: %s\n",szDateiPfad);
    

    Das öffnen von
    log1-040a.07
    log1-040b.07
    log1-040c.07
    log1-040d.07
    log1-040e.07
    log1-040f.07
    mit for (int i = 0x0A; i<0x10; i++) funktioniert komischerweise...

    Weiss jemand wieso ich o.g. Dateien nicht öffnen kann??

    Kann mann auch Buchstaben in einer for-Schleife hochzählen? Also von a --> f ?

    Mathias

    PS: Das Programm muss heute fertig werden 😞



  • Hier nochmal das komplette Programm. Vielleicht steigt ja jemand durch:

    #include <iostream>
    #include <fstream>
    #include <stdio.h>
    #include <string> 
    #include <stdlib.h> 
    
    using namespace std; 
    
    int main()
    {
    char szDateiPfad[50];
    std::string line, temp;
    
    cout << "                                   BOS TRACE\n";
    cout << "                                   *********" << endl <<endl;
    cout << "Bitte Pfad zu den log-files eingeben: ";
    cin >> temp;
    cout << endl;
    
    for (int i = 0x00; i<0x0A; i++)
      for (int j = 0x00; j<0x0A; j++)
    
      { 
      ifstream in; 
    
      sprintf(szDateiPfad,"%slog1-040%d.0%d",temp.c_str(),i,j);  
       printf("OEFFNE DATEI: %s\n",szDateiPfad);
       in.open(szDateiPfad, ios::in | ios::nocreate  );
    
      while (in.good()) 
      {
       getline(in, line); 
     //  printf("%s\n",line);
       ofstream out;
       out.open("C:\\bostrace\\temp.txt",ios::out|ios::app);
    
       int npos;
       while (!in.eof()) {
       getline(in, line);
       if (line.find("Field 0: ") != std::string::npos)
       out << line << "\n";
       if (line.find("Field 1: ") != std::string::npos)
       out << line << "\n";
    
      }  // 1.while
    
    }  // 2.while
    
    in.close();
    printf("SCHLIESSE DATEI: %s\n",szDateiPfad);
    cout << "---------------------------------------------------------------------";
    cout << endl;
    
    }   // for
    
    for (int i = 0x0A; i<0x10; i++)
      for (int j = 0x00; j<0x0A; j++)
    
      { 
      ifstream in; 
    
      sprintf(szDateiPfad,"%slog1-04%d.0%d",temp.c_str(),i,j);
       printf("OEFFNE DATEI: %s\n",szDateiPfad);
       in.open(szDateiPfad, ios::in | ios::nocreate  );
    
      while (in.good()) 
      {
       getline(in, line); 
     //  printf("%s\n",line);
       ofstream out;
       out.open("C:\\bostrace\\temp.txt",ios::out|ios::app);
    
       int npos;
       while (!in.eof()) {
       getline(in, line);
       if (line.find("Field 0: ") != std::string::npos)
       out << line << "\n";
       if (line.find("Field 1: ") != std::string::npos)
       out << line << "\n";
    
      }  // 1.while
    
    }  // 2.while
    
    in.close();
    printf("SCHLIESSE DATEI: %s\n",szDateiPfad);
    cout << "---------------------------------------------------------------------";
    cout << endl;
    
    }   // for
    
    for (int i = 10; i<20; i++)
      for (int j = 0x00; j<0x0A; j++)
    
      { 
      ifstream in; 
    
      sprintf(szDateiPfad,"%slog1-04%d.0%d",temp.c_str(),i,j);
      printf("OEFFNE DATEI: %s\n",szDateiPfad);
    
      in.open(szDateiPfad, ios::in | ios::nocreate  );
    
      while (in.good()) 
      {
       getline(in, line); 
     //  printf("%s\n",line);
       ofstream out;
       out.open("C:\\bostrace\\temp.txt",ios::out|ios::app);
    
       int npos;
       while (!in.eof()) {
       getline(in, line);
       if (line.find("Field 0: ") != std::string::npos)
       out << line << "\n";
       if (line.find("Field 1: ") != std::string::npos)
       out << line << "\n";
    
      }  // 1.while
    
    }  // 2.while
    
    in.close();
    printf("SCHLIESSE DATEI: %s\n",szDateiPfad);
    cout << "---------------------------------------------------------------------";
    cout << endl;
    
    }   // for
    
    for (int i = 0x1A; i<0x1F; i++)              //funktioniert nicht :(
      for (int j = 0x00; j<0x0A; j++)
    
      { 
      ifstream in; 
    
      sprintf(szDateiPfad,"%slog1-04%d.0%d",temp.c_str(),i,j);
      printf("OEFFNE DATEI: %s\n",szDateiPfad);
    
      in.open(szDateiPfad, ios::in | ios::nocreate  );
    
      while (in.good()) 
      {
       getline(in, line); 
     //  printf("%s\n",line);
       ofstream out;
       out.open("C:\\bostrace\\temp.txt",ios::out|ios::app);
    
       int npos;
       while (!in.eof()) {
       getline(in, line);
       if (line.find("Field 0: ") != std::string::npos)
       out << line << "\n";
       if (line.find("Field 1: ") != std::string::npos)
       out << line << "\n";
    
      }  // 1.while
    
    }  // 2.while
    
    in.close();
    printf("SCHLIESSE DATEI: %s\n",szDateiPfad);
    cout << "---------------------------------------------------------------------";
    cout << endl;
    
    }   // for
    
    std::string rnr, a;
      int npos;
    
       sprintf(szDateiPfad,"%sbostrace.txt",temp.c_str());
       ofstream out;
       out.open(szDateiPfad,ios::out|ios::app);
    
      ifstream in, in2;
    
      in.open("C:\\bostrace\\rufnrn.txt");
    
      while (!in.eof()) {
    
        getline(in, rnr);
    
            in2.open("C:\\bostrace\\temp.txt");
         while (!in2.eof()){
         getline(in2,line) ;
    
             if (((line.find(rnr) != std::string::npos) && line.find("Field 0") != std::string::npos))
                 {
                  out << line ;
                  cout << line;
                  getline(in2,line) ;
    
                   if (line.find("Field 1") != std::string::npos)
    
                   out << line << "\n";
                   cout << line << "\n";
                 }
    
           }
          in2.close();
        }
    }   // main
    


  • du könntest zur leselichkeit wenigstens in kommentaren angeben, dass du von 26 bis 31 und von 0 bis 10 zaehlst, die hex ist etwas komisch. vielleicht solltest du bei sprintf (was du in c++ eh nicht umbedingt verwernden solltest, lieber stringstreams) angeben, dass du keine dezimale, sondern hexadezimale ausgeben willst. (bei stringstreams der modifikator hex, soweit mich das nicht täuscht).
    dsa problem ist: nur weil du in eine int variable einen wert in hex-format einspeicherst, speichert er ganz genauso nur eine 8-32 bit kombination, der hex ist nur, damit du besser lesen kannst. also musst du bei de3r ausgabe auch sagen, dass du speziell hex haben willst

    edit: und entscheid dich mal: nimm c oder c++! also printf _oder_ cout



  • Hi! danke für deine antwort. werde das cout zu printf und cin zu getline ändern.

    kannst du mir bitte kurz erklären wie ich das machen soll:

    "also musst du bei de3r ausgabe auch sagen, dass du speziell hex haben willst"

    ??

    Ist es eigentl auch möglich Dateien zu öffnen u unter einem anderen dateinamen abzuspeichern? Wenn ja, wie würde das funktionieren?

    Gruß, Mathias



    1. ausgabe von Hex werten:
    cout << hex << 0x1A << endl;
    
    1. abspeichern unter anderem namen (nur schnell hingehackt, nicht wirklich guter code, nur als beispiel):
    ifstream in("altedatei");
    ofstream out("neuedatei");
    string tmp;
    in >> tmp;
    out << tmp;
    //noch datei löschen
    

Anmelden zum Antworten