I've got this annoying "access violation" problem. I've done searching for a whole day on the Internet and although I didn't find any solution specific to my problem I do understand "unhandled exception in abc.exe:0xC0000005: Access Violation" has something to do with inappropriate use of pointers.
However where the error occurs(see the code) there is no reference to any pointer I've defined previously. I also noticed that although when output is called the parameter 'printtype' is set to 2, the program nevertheless executed 'out5.open("designpoints.txt",ios::app);" and the error box popped up.
void output(struct a *pointer, int num, int printtype)
{
int i,j;
ofstream out5;
if(printtype==0)
out5.open("designpoints.txt");
else if(printtype=1)
out5.open("designpoints.txt",ios::app);//where the error occurred
else
out5.open("NDlist.txt");
/****output stuff*************/
out5.close();
}
int main()
{
/*the struct is defined here and abc is the name of an array of this particular struct*/
output(abc,10,2);
}
Whenever the message box popped up with the ubiquitous access violation thing and I clicked the ok button I invariably were asked to provide the file path to "stream.c", or "setlocal.c". It also says there no file by such a name was found in the directory. If I close this window i'd be taken to, invariably, some wierd code window showing the content of "xlocal.h" or sometimes codes such as the following
00439ED9 mov byte ptr [eax],0
00439EDC mov dword ptr [i],1
00439EE3 jmp _setlocale_get_all+4Eh (00439eee)
00439EE5 mov ecx,dword ptr [i]
00439EE8 add ecx,1
00439EEB mov dword ptr [i],ecx
00439EEE mov edx,dword ptr [i]
00439EF1 imul edx,edx,0Ch
00439EF4 mov eax,dword ptr ___lc_category+4 (004a0dc4)[edx]
00439EFA push eax
00439EFB push offset string "=" (004973b4)
00439F00 mov ecx,dword ptr [i]
00439F03 imul ecx,ecx,0Ch
00439F06 mov edx,dword ptr ___lc_category (004a0dc0)[ecx]
00439F0C push edx
00439F0D push 3
00439F0F mov eax,[___lc_category+4 (004a0dc4)]
00439F14 push eax
00439F15 call _strcats (0043a140)
00439F1A add esp,14h
00439F1D cmp dword ptr [i],5
00439F21 jge _setlocale_get_all+0C9h (00439f69)
00439F23 push offset string ";" (004973a0)
00439F28 mov ecx,dword ptr [___lc_category+4 (004a0dc4)]
00439F2E push ecx
00439F2F call strcat (00440de0)
00439F34 add esp,8
00439F37 mov edx,dword ptr [i]
00439F3A add edx,1
I want the program to write the content of the struct a to a file, simple as that. output() takes the pointer abc that points to the start address of a certain struct I've clearly defined before calling output(). I've checked that pointer abc pointed to a valid struct I've created and it could not have caused any problem. compile and link did not mention any problem with my code.
I have a hunch that this has to do with my use of ofstream. Any help would be appreciated.