Alles was nach while Schleife kommt nicht beachtet...
-
Hi,
ich habe ein Problem, bei dem ich auf keinen grünen Zweig komme. Alles, was nach der while Schleife im folgenden Quellcode kommt, wird nicht beachtet und einfach nicht ausgeführt,void* red_function(void *data) { ///Variables declaration fstream f; string in; ifstream input; ///Open readable stream input.open("cpp.ppm"); ///Initialize the variables int farbe = 0; int zahl = 0; int i = 0; ///Read the first line getline(input, in); ///Run through the file cout << "Hallo" << endl; while(!input.eof()) { ///If an unusable string was found if(((signed int)in.find("#", 0) != -1) || ((signed int)in.find( "P3", 0 ) != -1)) { ///Get the next line getline(input, in); ///And continue with the next step in the while loop continue; } ///If i is 0 if(i == 0) { ///Increase i i++; ///and read the next line getline(input, in); continue; ///if i is 1 }else if(i == 1) { ///increase i i++; ///initialize a stringstream stringstream sstr(in); ///and pipe it into an integer sstr >> zahl; ///initialize the array for the red values red = new int[zahl+2]; ///put an ending condition to the end red[zahl+1] = -1; ///get the next line getline(input, in); continue; ///if i is 2 } else if(i == 2) { ///if farbe is 0, increase the value in the array for the red values ///at the position of the fitting value if(farbe == 0) { stringstream sstr(in); sstr >> zahl; red[zahl] += 1; farbe++; } else if(farbe == 1){ farbe++; } else if(farbe == 2) { cout << farbe << endl; farbe = 0; } getline(input, in); continue; } } ///Close the input-stream input.close(); ///Pipe the values into the file f.open("red_histogram.dat", ios::out); for (int j = 0; red[j] != -1; j++) { cout << j << " " << red[j] << endl; f << j << " " << red[j] << endl; } f.close(); return NULL; }Ich hoffe irgendwer sieht den Fehler.
Liebe Grüße
René
-
Bist du schon mit dem Debugger durch?
-
Hi,
nein, ich weiß nicht wie ich unter Eclipse pthreads zum Laufen bekomme. Diese kommen im Gesamtprogramm vor.
-
Woher weißt du dann, dass der Teil nach der Schleife übersprungen wird? Zur Not hilft die Holzhammermethode mit Konsolenausgaben um das festzustellen.
-
Ja, in der Konsole habe ich das Programm ja auch schon laufengelassen. Und ich habe mit cout nach der Schleife versucht etwas auszugeben. Aber das wird nicht ausgegeben. Gebe ich hingegen innerhalb der Schleife zum Beispiel die Variable farbe aus, funktioniert es.
-
ich hab zwar keine Dateien, die da eingelesen werden, aber bei mir bricht das Programm mit einer Exception ab.
Für mich ist unklar was in der Variablen "zahl" drin steht, wodurch dann Speicher für den int reserviert wird. (Wo wird der freigegeben? )
In der for-Schleife hab ich dann teilweise Zugriffsfehler.
Vielleicht zum Testen mal nen Inhalt zur Verfügung stellen.