Unbekannter Fehler
-
[cpp]#include <io.h>
#include <conio.h>
#include <string.h>#include <windows.h>
struct CSV_Y{
char *text;
};struct CSV_X{
CSV_Y y[100];
};struct CSV_TABLE{
CSV_X x[150];
};struct CSV_RESULT{
CSV_Y y[150];
};class CSV{
public:static CSV_TABLE read(char fpath){
int x = 0,
y = 0,
z = 0;
CSV_TABLE out;
char buffer = new char[5000];
FILE *f = fopen(fpath,"r");if(f == NULL){
return out;
}
for(int i1 = 0; i1 <= 500;i1++){
for(int i2 = 0; i2 <= 500;i2++){
out.x[i1].y[i2].text=new char[1024];
out.x[i1].y[i2].text[0]=0;
}
}
x=y=z=0;
while(fgets(buffer,5000,f)){
for(int i = 0; i < (int)strlen(buffer) ; i ++){
out.x[x].y[y].text[z] = buffer[i];
z++;
if(buffer[(i+1)]==';'){
out.x[x].y[y].text[z]=NULL;
y ++;
z = 0;
i++;
}
}
x ++;
y = 0;
}
fclose(f);
return out; <------------------------------- Hier kommt der Fehler
}static CSV_TABLE find(CSV_TABLE table, char *tofind){
int x = 0,
y = 0;
int rx = 0;
CSV_TABLE out;while(table.x[x].y[0].text!=NULL){
while(table.x[x].y[y].text!=NULL){
if(0 == strcmp(table.x[x].y[y].text,tofind)){
out.x[rx] = table.x[x];
rx ++;
x ++;
}
y ++;
}
x ++;
}
return out;
}static CSV_TABLE findEx(CSV_TABLE table, char *tofind, int y){
int x = 0;
int rx = 0;
CSV_TABLE out;while(table.x[x].y[0].text!=NULL){
if(0 == strcmp(table.x[x].y[y].text,tofind)){
out.x[rx] = table.x[x];
rx ++;
x ++;
}
x ++;
}
return out;
}/*static CSV_RESULT result(CSV_TABLE table, int result_no){
CSV_RESULT out;
if( table.x[result_no].y[0].text != NULL ){
for( int i = 0; table.x[result_no].y[i].text != NULL ; i ++){
out.y[i].text = table.x[result_no].y[i].text;
}
return out;
}
return out;
}*/};[/cpp]
An der markierten Stelle kommt:
Run-Time Check Failure #2 - Stack around the variable 'out' was corrupted.
Wenn ich dann auf 'Weiter' klicke kommt:
Unhandled exception at 0x058114aa in CSV.exe: 0xC0000005: Access violation reading location 0xffffffff.
So wird der Code ausgeführt:
CSV_TABLE tbl; tbl = CSV::read("error.csv"); printf("strlen() -> %i",strlen(tbl.x[1].y[0].text)); printf("%s",tbl.x[1].y[0].text);
Warum kommt das und wie kann ich den Fehler beheben?
-
Hi!
Du hast was vergessen:Die Tabelle sieht so aus:
1.1;1.2;1.3;1.4
2.1;2.2;2.3;2.4
3.1;3.2;3.3;3.4
-
Dieser Thread wurde von Moderator/in Unix-Tom aus dem Forum MFC mit dem Visual C++ in das Forum C++ verschoben.
Im Zweifelsfall bitte auch folgende Hinweise beachten:
C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?Dieses Posting wurde automatisch erzeugt.
-
D.Derigs schrieb:
for(int i1 = 0; i1 <= 500;i1++){ for(int i2 = 0; i2 <= 500;i2++){
Weder x noch y haben 501 Elemente.