Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Illegal Operation when assigning char* to string

Status
Not open for further replies.

biot023

Programmer
Nov 8, 2001
403
0
0
GB
Hallo.
My program keeps bombing out with an Illegal Operation message whenever the code on line 5 (following) is attempted:
1) string build_str;
2) char buffer[255];
3) ifstream file("ini_file.ini");
4) file.getline(buffer,255);
5) build_str=buffer;

This has been working okay so far, so I can only assume a wierd bug of some description.
Has anyone come across this & does anyone have any ideas for workarounds?
Any help gratefully received.
Cheers,
Douglas JL

Common sense is what tells you the world is flat.
 
instead of using

build_str=buffer
/*buffer without the [] is just a pointer to the first element in array*/

try

strcpy(build_str,buffer);

----------------------------------------
Friends are generally of the same sex, for when men and women agree,it is only in the conclusions; their reasons are always different.
 
Cheers, man - but I'm pretty certain that this is a bug.
I had it fixed for the above problem by declaring the variable build_str elsewhere (in this case as a static member of the class).
Unfortunately, now I have the same error as soon as I try to compile - even before I can browse into code!
Man!
Anyone any ideas?
Cheers,
Douglas JL

Common sense is what tells you the world is flat.
 
I am somtimes so sure it is the software that is
at fault that it becomes dificult to admit that it is
my code.

tomcruz.net
 
I know what you mean - but this was all working fine until I made a small change to the code. Then I got the error, and not even restoring the code to how it was before the error gets rid of it.
I know that BCB sometimes tries to write variables to the same address (for no apparent reason), so I'm thinking maybe that this is what is occuring during program setup.
I guess I'll just have to jiggle variables until something works.
I'll keep my progress (if there is any!) posted here, and if anyone has any really bright ideas in the meantime, I'd be VERY grateful to hear them - this damn' thing was supposed to be done last week!
Continued thanks,
Douglas JL

Common sense is what tells you the world is flat.
 
Just for reference, this is what I am told when I ask for details of the illegal operation:

DATMAN_ARCHIVE_ caused an invalid page fault in
module DATMAN_ARCHIVE_.EXE at 0167:0047fea5.
Registers:
EAX=00610134 CS=0167 EIP=0047fea5 EFLGS=00010203
EBX=0070fc44 SS=016f ESP=0060ffa4 EBP=00610104
ECX=006101d8 DS=016f ESI=819b42f8 FS=543f
EDX=bff76855 ES=016f EDI=00610200 GS=0000
Bytes at CS:EIP:
53 56 57 8b 7d 08 b8 98 64 4b 00 e8 73 69 ff ff
Stack dump:

Dunno if that's of any use to anyone, though...
Cheers,
DJL

Common sense is what tells you the world is flat.
 
Well, the moral of this tale appears to be stop being so damn' lazy with the updates!
I just downloaded & installed Update pack 4 from Borland, & my problem disappeared. I dunno if that's cuz there was a fix for it, or if something got jiggled, but it's done the trick, either way.
Hopefully another frustrated idiot like me will find this post & be saved much blood & many tears!
Douglas JL

Common sense is what tells you the world is flat.
 
Now get back to work your still a week behind.

:)

tomcruz.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top