I wrote this Programm it reads out something from a file something like:
1 2 G O B Y
11 3 O B B Y
from a .txt file called anfangsanordnung.txt.
However this is the programm:
Expand|Select|Wrap|Line Numbers
- int main()
- {
- fstream f;
- char cstring[256];
- char color[6];
- int x=0,y=0,var=0,var2=0;
- int zahl;
- f.open("anfangsanordnung.txt", ios::in);
- if (!f.eof()){f.getline(cstring, sizeof(cstring));}
- while (!f.eof())
- {
- i=0;
- x=0;
- y=0;
- var=0;
- var2=0;
- while (cstring[i]==' '){i++;}
- while (cstring[i]!=' ')
- {
- zahl = cstring[i] - '0';
- x=x*10+zahl;
- i++;
- }
- i++;
- i++;
- while (cstring[i]!=' ')
- {
- zahl = cstring[i] - '0';
- y=y*10+zahl;
- i++;
- }
- i++;
- while (var2<4)
- {
- while (cstring[i]!=' ')
- {
- color[var]=cstring[i];
- var++;
- i++;
- }
- i++;
- if (color[0]=='B'){steine[x-1][y-1][var2]=0;var2++;}
- if (color[0]=='G'){steine[x-1][y-1][var2]=1;var2++;}
- if (color[0]=='O'){steine[x-1][y-1][var2]=2;var2++;}
- if (color[0]=='Y'){steine[x-1][y-1][var2]=3;var2++;}
- var=0;
- }
- f.getline(cstring, sizeof(cstring));
- }
- f.close();
- cout << "finsihed" << endl;
- }
*** stack smashing detected ***: ./out terminated
Am I getting getline() or .eof() wrong these are the only two lines new to me ??
Thanks