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?