file output/character sequences

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
void use(char buffer[])
{
	int last=getlastinstring(buffer);
	int aux1;
	char name[10];
	for(aux1=0;aux1<last;aux1++)
	{
		name[aux1]=buffer[aux1+4];
	}
	char line[500];
	fstream varfile;
	varfile.open("C:/mycmd/sysfiles/var.bin");
	   varfile>>line;
    varfile.close();
	last=getlastinstring(line);
	for(aux1=0;aux1<last;aux1++)
	{
		if(line[aux1]==name[0]&&line[aux1+1]==name[1])
			break;
	}
	int begname=aux1;
	int lastname=getlastinstring(name);
	int _char=begname+lastname;
	char number[4];
	int _char2=getplacecharafter(line,'|',_char);
	for(aux1=0;aux1<_char2-_char;aux1++)
	{
		number[aux1]=line[_char+aux1+1];
	}
	int nmb;
	stringstream(number)>>nmb;
	varflag=nmb;
}
void delvar(char buffer[])
{
	 char name[25];
	 int buffersize=getlastinstring(buffer);
	 int aux;
	 for(aux=0;aux<buffersize;aux++)
	 {
		  name[aux]=buffer[aux+7];
	 }
	 int namesize=getlastinstring(name);
	 namesize=namesize+6;
	 char line[500];
	 char null[500];
	 int p;
	 for(p=0;p<500;p++)
	 {
		 null[p]=' ';
	 }
	 fstream file;
	 file.open("C:/mycmd/sysfiles/var.bin");
		file>>line;
		file.close();
	 int lenght=getlastinstring(line);
	 for(aux=0;;aux++)
	 {
		 if(line[aux]==name[0]&&line[aux+1]==name[1])
			 break;
	 }
	 int begin=aux;
	 for(;begin<=lenght;begin++)
	 {
		 line[begin]=line[begin+namesize];
	 }
	 int place=getplacecharafter(line,'|',aux);
	 fstream bfile;
	 bfile.open("C:/mycmd/sysfiles/var.bin");
	 bfile<<null;
	 bfile.close();
	 fstream xfile;
	 line[place]=NULL;
	 xfile.open("C:/mycmd/sysfiles/var.bin");
	 xfile<<line;
	 xfile.close();
     cout<<"Deleted variable "<<name<<endl;
}

I have a file var.bin with this content:
sysvar_1|null_0|
a varaloc function creates more variables:
sysvar_1|null_0|name_00000|
with the use function I try to get the value for a variable.The buffer looks like:use_varname;
with the delvar function I try to delete a variable.
In the first function,i get the value for the global varflag,but then the program crashes.IN the second case,the function deletes everythin after null_0|.
Can someone tell what's wrong?
Topic archived. No new replies allowed.