Stack Overflow direkt nach Eintritt in Main (Was gehtn hier?)
-
Hallo zusammen!
Naja, ich sitz' in der Schule und mir ist langweilig, also wollte kurz zwei verschiedene Sortieralgos vergleichen.
Leider aber stürzt das Programm jedes mal mit Stack Overflow ab, noch bevor die erste Anweisung in der Main ausgeführt wird (sowohl beim Debug- wie auch beim Release-Binary).
Ein normales Hello World in der gleichen Datei wird aber anstandslos ausgeführt...Hier mal der Code, vllt. wird jemand schlau draus:
// BöbbuSort.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung. // #include <stdio.h> #include <iostream> #include <time.h> const int filesize = 1024*1024*10; using namespace std; void bubble(char *str); void boebbu(char *str); int main() { char buf[256]; FILE *f = 0; while(!f) { cout << "pfad?: "; cin >> buf; f = fopen(buf,"r"); } char content[filesize]; char content2[filesize]; fread(content,sizeof(char),filesize,f); fclose(f); strcpy(content2, content); time_t t1, t2; time_t start = time(0); bubble(content); t1 = time(0) - start; start = time(0); boebbu(content2); t2 = time(0) - start; cout << "bubble: " << t1 << "\nboebbu: " << t2; cout << "\n\n\n"; cin >> buf; return 0; } void bubble(char *str) { int l = strlen(str); char c; for(int i = 0; i < l; i++) { for(int j = 0; j < l-i-1; j++) { if(str[j] > str[j+1]) { c = str[j]; str[j] = str[j+1]; str[j+1] = c; } } } } void boebbu(char *str) { int chars[256]; int l = strlen(str); for(int i = 0; i < l; i++) { ++chars[(int)str[i]]; } int pos = 0; for(int i = 0; i < 256; i++) { for(int j = 0; j < chars[j]; j++) { str[pos++] = (char)i; } } }
Danke schon mal, wer sich die Mühe macht
-
du hast über 20MB auf dem stack
-
hab ich mir auch schon gedacht, aber sowohl reduzieren der filesize auf 1024 sowie reservieren des speichers auf dem heap erzeugt die gleiche meldung
-
Doch, bei mir geht das mit
const int filesize = 1024;