Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cstdlib>
- #include <string>
- #include <vector>
- #include <sstream>
- #include <limits> // numeric_limits
- void MatrixMase(std::string Datei_Name, long * hoehe, long * breite);
- std::string BestimmteZeileAusDatei(std::string Datei_Name, long Gesuchte_Zeile_Wert);
- long BestimmtenWertAusZeileLesen(std::string Gesuchte_Zeile_Inhalt, long Stelle);
- long LeerzeichenAbstandEinerZeileErmitteln(std::string Gesuchte_Zeile_Inhalt);
- int main ()
- {
- using namespace std;
- long hoehe,breite,a,b,c,d,e,wert;
- a = 0;
- b = 4;
- c = 0;
- d = 0;
- e = 0;
- wert = 0;
- long counter;
- using namespace std;
- string Datei_Name = "input.pgm";
- string Bestimmte_Zeile_Aus_Datei;
- string Wert_String;
- MatrixMase(Datei_Name, &hoehe, &breite);
- long MatrixA[breite][hoehe];
- Bestimmte_Zeile_Aus_Datei = BestimmteZeileAusDatei( Datei_Name, b);
- for(int i = 0; i != (breite * hoehe); i++, a++, c++)
- {
- Bestimmte_Zeile_Aus_Datei = BestimmteZeileAusDatei( Datei_Name, b);
- if(a > (Bestimmte_Zeile_Aus_Datei.length() / LeerzeichenAbstandEinerZeileErmitteln(Bestimmte_Zeile_Aus_Datei) - 1))
- {
- a = 0;
- b++;
- }
- Bestimmte_Zeile_Aus_Datei = BestimmteZeileAusDatei( Datei_Name, b);
- for(counter = 0, e = 0; e < a ; counter++)
- {
- if(Bestimmte_Zeile_Aus_Datei[counter] == ' ')
- {
- e++;
- }
- }
- Wert_String = ' ';
- for(; Bestimmte_Zeile_Aus_Datei[counter] != ' '; counter++)
- {
- Wert_String += Bestimmte_Zeile_Aus_Datei[counter];
- }
- stringstream Wert_String_1(Wert_String);
- Wert_String_1 >> wert;
- if(c > breite)
- {
- c = 0;
- d++;
- }
- MatrixA[c][d] = wert;
- }
- return(0);
- }
- void MatrixMase(std::string Datei_Name, long * hoehe, long * breite)
- {
- using namespace std;
- long Gesuchte_Zeile_Wert = 2;
- string Gesuchte_Zeile_Inhalt;
- Gesuchte_Zeile_Inhalt = BestimmteZeileAusDatei(Datei_Name, Gesuchte_Zeile_Wert);
- *breite = BestimmtenWertAusZeileLesen(Gesuchte_Zeile_Inhalt, 0);
- *hoehe = BestimmtenWertAusZeileLesen(Gesuchte_Zeile_Inhalt, 1 * LeerzeichenAbstandEinerZeileErmitteln( Gesuchte_Zeile_Inhalt));
- return;
- }
- std::string BestimmteZeileAusDatei(std::string Datei_Name, long Gesuchte_Zeile_Wert)
- {
- using namespace std;
- ifstream Datei(Datei_Name.c_str());
- if( !Datei.is_open()){ return("Fehler1");};
- for( ; Gesuchte_Zeile_Wert > 1; --Gesuchte_Zeile_Wert)
- {
- Datei.ignore(numeric_limits< streamsize >::max(), '\n' );
- }
- string Gesuchte_Zeile_Inhalt;
- if( !getline( Datei, Gesuchte_Zeile_Inhalt)){ return("Fehler2");};
- return(Gesuchte_Zeile_Inhalt);
- }
- long BestimmtenWertAusZeileLesen(std::string Gesuchte_Zeile_Inhalt, long Stelle)
- {
- using namespace std;
- long strpos = Gesuchte_Zeile_Inhalt.find(" ") + 1;
- string Gesuchter_String = Gesuchte_Zeile_Inhalt.substr( Stelle, strpos);
- stringstream Gesuchter_Stringsrteam(Gesuchter_String);
- long Wert;
- Gesuchter_Stringsrteam >> Wert;
- return(Wert);
- }
- long LeerzeichenAbstandEinerZeileErmitteln(std::string Gesuchte_Zeile_Inhalt)
- {
- return(Gesuchte_Zeile_Inhalt.find(" ") + 1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement