Hi all
here is my problem:
I tried to write a simple console application to re-format some simple lines of text. These lines are quite simmilar, for example:
thats what they look like:
M Z4.3.1_Z Dist 69.53 70.00 0.10 -0.10 -0.47 -0.37
M Z4.3.2_Z Dist 69.71 70.00 0.10 -0.10 -0.29 -0.19
M Z4.3.3_Z Dist 69.69 70.00 0.10 -0.10 -0.31 -0.21
M Z4.3.4_Z Dist 69.62 70.00 0.10 -0.10 -0.38 -0.28
and thats what a want to get:
Mass Z4.3.1_Z Soll: 70.00 +0.10/-0.10 Ist: 69.53
Mass Z4.3.2_Z Soll: 70.00 +0.10/-0.10 Ist: 69.71
Mass Z4.3.3_Z Soll: 70.00 +0.10/-0.10 Ist: 69.69
Mass Z4.3.4_Z Soll: 70.00 +0.10/-0.10 Ist: 69.62
i just want to save the upper example and get the lower in another txt file.
the problem is: either Windows or Code::Blocks terminates the process because of an memory exception.
It tells me following:
"The assignment in "0x00401522" directs on memory in "0x00672128". The action "written" could not be executed on/in the memory"
sorry for the wacky translation, but the original text is in german and says:
"Die Anweisung in "0x00401522" verweist auf Speicher in "0c00672128". Der Vorgang "written" konnte nicht auf dem Speicher durchgeführt werden."
then the error window asks me if i want to debug or terminate the program.
back in the CB window there is following in the Build LOG: Process terminated with status -1073741819 (0 minutes, 6 seconds)
now here comes the code (its a bit crappy but it will do fine for me, or at least i hope so; i'm also quite new to cpp and CB so i tried my best to avoid mistakes, but there are some passages i wrote like i used to do in C; it's simply a little bit complicatet :?)
/*
Geschrieben in Code::Blocks
*/
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string>
#include<fstream>
#include<iostream>
using namespace std;
struct format
{
private:
public:
int i, j, k;
int leercount, LFcount, zaehler;
string aufbereitet, formatiert;
string a, b, c, d, e;
};
int main()
{
struct format X;
ifstream lesen;
ofstream schreiben;
//Aufbereiten
X.leercount=0;
lesen.open("Eingabe.txt");
while(!lesen.eof())
{
X.aufbereitet[X.i]=lesen.get();
X.i++;
if(X.aufbereitet[X.i-1]==32)
{
X.aufbereitet[X.i]=lesen.get();
while(X.aufbereitet[X.i]==32)
{
if(X.aufbereitet[X.i]==32)
X.aufbereitet[X.i]=lesen.get();
}
X.leercount++;
X.i++;
}
if(X.aufbereitet[X.i-1]==10)
{
X.aufbereitet[X.i]=lesen.get();
while(X.aufbereitet[X.i]==10)
{
if(X.aufbereitet[X.i]==10)
{
X.aufbereitet[X.i]=lesen.get();
}
}
X.LFcount++;
X.i++;
}
}
//Kontrolle der Zählvariablen
printf("\nKontrolle 1:\nZeilenumbrueche: %d\nLeerzeichen: %d",X.LFcount,X.leercount);
getch();
//Neuzuordnen und Umformatieren der Daten
while(X.zaehler<X.LFcount)
{
X.i=0;
X.j=0;
if(X.aufbereitet[X.i]==32)
X.leercount++;
if(X.leercount==1+(X.zaehler*8))
{
X.i++;
while(X.aufbereitet[X.i]!=32);
{
X.a[X.j]=X.aufbereitet[X.i];
X.i++;
X.j++;
}
}
if(X.leercount==3+(X.zaehler*8))
{
X.i++;
while(X.aufbereitet[X.i]!=32);
{
X.b[X.j]=X.aufbereitet[X.i];
X.i++;
X.j++;
}
}
if(X.leercount==4+(X.zaehler*8))
{
X.i++;
while(X.aufbereitet[X.i]!=32);
{
X.c[X.j]=X.aufbereitet[X.i];
X.i++;
X.j++;
}
}
if(X.leercount==5+(X.zaehler*8))
{
X.i++;
while(X.aufbereitet[X.i]!=32);
{
X.d[X.j]=X.aufbereitet[X.i];
X.i++;
X.j++;
}
}
if(X.leercount==6+(X.zaehler*8))
{
X.i++;
while(X.aufbereitet[X.i]!=32);
{
X.e[X.j]=X.aufbereitet[X.i];
X.i++;
X.j++;
}
}
X.i++;
X.formatiert += ("Mass %s Soll: %s %s/%s Ist: %s\n",X.a,X.b,X.c,X.d,X.e);
X.zaehler++;
}
schreiben.open("Ausgabe.txt");
schreiben << X.formatiert;
schreiben.close();
return 0;
}
I hope someone heare can help me, becaue i need this program ASAP
Thanks for reading my problem and maybe for helping me!!!