473,568 Members | 2,964 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

access violation problem


int main()
{
char record_typec = 'c';
record_typec = toupper(record_ typec);
* rec->Newcrecord.rec ord_type = record_typec;

etc
etc

\************** *************** *************** *\

I've run a debug on the program and this is where I'm encountering the access
violation problem. I've tried the dot operator to access the structure but that
doesn't appear to work. How can change the syntax and avoid the access
violation error?
Jul 22 '05 #1
13 2192
"JasBascom" <ja*******@aol. com> wrote in message
news:20******** *************** ****@mb-m11.aol.com
int main()
{
char record_typec = 'c';
record_typec = toupper(record_ typec);
* rec->Newcrecord.rec ord_type = record_typec;

etc
etc

\************** *************** *************** *\

I've run a debug on the program and this is where I'm encountering
the access violation problem. I've tried the dot operator to access
the structure but that doesn't appear to work. How can change the
syntax and avoid the access violation error?

Since most people here lack psychic abilities, I suggest that you tell us
how rec is defined.
--
John Carson
1. To reply to email address, remove donald
2. Don't reply to email address (post here instead)

Jul 22 '05 #2
JasBascom wrote:

int main()
{
char record_typec = 'c';
record_typec = toupper(record_ typec);
* rec->Newcrecord.rec ord_type = record_typec;

etc
etc

\************** *************** *************** *\

I've run a debug on the program and this is where I'm encountering the
access violation problem. I've tried the dot operator to access the
structure but that doesn't appear to work. How can change the syntax
and avoid the access violation error?


How would anyone hwere know? What is rec? Where is it defined? It seems
to be a pointer, so where did you let it point to something? What is
the '*' at the beginning of the last line supposed to do?

Jul 22 '05 #3
rec is the pointer to a union
it is declared thus union Allrecords* rec.
Now that you know what rec is does that help you to help me?
Jul 22 '05 #4
"JasBascom" <ja*******@aol. com> wrote in message
news:20******** *************** ****@mb-m11.aol.com
rec is the pointer to a union
it is declared thus union Allrecords* rec.
Now that you know what rec is does that help you to help me?


Yes. A pointer simply stores a memory address. Thus rec is meant to store
the address of an instance of Allrecords. However, you never create an
instance of Allrecords (as far as one can tell from the still-limited
information that you have provided), so rec never gets the chance to perform
its proper function. Instead, whatever value rec is storing points to memory
that you don't own and hence you get an access violation when you try to
write to it. You could create an instance of Allrecords with the following:

union Allrecords* rec = new Allrecords;

which allocates memory for an instance of Allrecords and makes rec point to
it. You could also forget about pointers and just declare:

union Allrecords rec_obj;

to create an Allrecords object called rec_obj.

Whether you are accessing the members of this structure correctly with

* rec->Newcrecord.rec ord_type = record_typec;

is again impossible to tell without seeing the definition of Allrecords.
--
John Carson
1. To reply to email address, remove donald
2. Don't reply to email address (post here instead)

Jul 22 '05 #5
On 20 Feb 2004 13:46:17 GMT in comp.lang.c++, ja*******@aol.c om
(JasBascom) was alleged to have written:
int main()
{
char record_typec = 'c';
record_typec = toupper(record_ typec);
* rec->Newcrecord.rec ord_type = record_typec;

etc


Variable "rec" is never declared above.
"Newrecord" is never declared above.
etc.

Post small, simplified but COMPLETE and COMPILEABLE samples so people
don't have to guess what you are talking about.

This issue is covered in Marshall Cline's C++ FAQ. See the topic
"[5.8] How do I post a question about code that doesn't work correctly?"
It is always good to check the FAQ before posting. You can get the FAQ
at:
http://www.parashift.com/c++-faq-lite/

Jul 22 '05 #6
The full program is follows. Thank you john for pointing out the access
violation error. i also have a problem with the declaring of an fstream object
- sort_file. For some reason my debugger is unable to move beyond that point in
the code.

I would also like to have rec.Newcrecord. record_type assigned the character 'c'
and to toupper the record_type. can you please help in both instances.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstring>
#include <cstdlib>
using namespace std;

struct crecord {
char record_type;
char customercode[5];
char customername[21];
char customeraddress[61];
char customerbalance ;
char creditlimit;
int Totalbalance;
int Totalcreditlimi t;

};
struct irrecord {
char record_type;
char customercode[5];
char partnum[6];
char issue_rec[5];

};
struct drecord {
char record_type;
char customercode[5];
};
int loop = 200;
long offset = 1;

union Allrecords{
struct crecord Newcrecord;
struct irrecord Newirrecord;
struct drecord Newdrecord;

};
union Allrecords* rec;


void sort_function( union Allrecords* rec, fstream& validdata )
{

union Allrecords *str_ptr1, *str_ptr2, tempstr;
for(int i =0; i< loop; i++)
while( strcmp(str_ptr1[i].Newcrecord.cus tomercode, '\0') ||
strcmp(str_ptr1[i].Newdrecord.cus tomercode, '\0') ||
strcmp(str_ptr1[i].Newirrecord.cu stomercode, '\0'))
{
str_ptr2 = str_ptr1 + 1;//set to next element.

for( i=0; i<loop; i++)
while( strcmp(str_ptr2[i].Newcrecord.cus tomercode, '\0') ||
strcmp(str_ptr2[i].Newdrecord.cus tomercode, '\0'))
{
for(int i=0; i<loop; i++)
if( strcmp( str_ptr1[i].Newirrecord.cu stomercode,
str_ptr2[i].Newirrecord.cu stomercode + 1))
{
tempstr = *str_ptr1;
*str_ptr1 = *str_ptr2;
*str_ptr2 = tempstr;

}
*str_ptr1++;//incremented, so that the same code isn't sorted again
}
str_ptr2++;
}

}



int main()
{
const char sorted_file[] = "A:\\514650SDP2 .txt";
const char outfile[] = "A:\\514650VDP1 .bin";


long offset = 1;
int filesize;
int reccount;

fstream sort_file;
fstream validdata;

sort_file.open( "A:\\514650SDP2 .txt", ios::out);
if(!sort_file)
{
cout<<"Cannot create file"<< endl;
return EXIT_FAILURE;
};

validdata.open( "A:\\514650VDP1 .bin", ios::in || ios::binary);
if(!validdata)
{
cout<<" Cannot find file"<<endl;
return EXIT_FAILURE;
};
validdata.seekg (-offset, ios::end);
filesize = validdata.tellg ();
validdata.seekg (offset, ios::beg);

reccount = sizeof(filesize )/sizeof(Allrecor ds);
rec = new(Allrecords[reccount]);
validdata.read( (char*) rec, filesize);//read the whole file.

for(int i =0; i <reccount; i++)
{
switch(rec[i].Newdrecord.rec ord_type)
{
case 'c':
case 'C':
case 'i':
case 'I':
case 'r':
case 'R':
case 'd':
case 'D':
sort_function(r ec, validdata);
default:;
};

};

return 0;

}


Jul 22 '05 #7
On 20 Feb 2004 16:57:46 GMT in comp.lang.c++, ja*******@aol.c om
(JasBascom) was alleged to have written:
while( strcmp(str_ptr1[i].Newcrecord.cus tomercode, '\0') ||


Note that '\0', being a const integral expression with a value of zero,
is a valid C++ null pointer. But not what you wanted. What you wrote
is equivalent to

while( strcmp(str_ptr1[i].Newcrecord.cus tomercode, NULL) ||

while I think what you wanted is

while( strcmp(str_ptr1[i].Newcrecord.cus tomercode, "") ||
Jul 22 '05 #8
On 20 Feb 2004 16:57:46 GMT in comp.lang.c++, ja*******@aol.c om
(JasBascom) was alleged to have written:
validdata.open( "A:\\514650VDP1 .bin", ios::in || ios::binary);


Wrong, need bitwise or, not boolean or, should be

validdata.open( "A:\\514650VDP1 .bin", ios::in | ios::binary);

Jul 22 '05 #9
On 20 Feb 2004 16:57:46 GMT in comp.lang.c++, ja*******@aol.c om
(JasBascom) was alleged to have written:
for(int i=0; i<loop; i++)
if( strcmp( str_ptr1[i].Newirrecord.cu stomercode,
str_ptr2[i].Newirrecord.cu stomercode + 1))

{
OK, I give up on following the logic of your sort function. Especially
with all the comparison tests mixed in with the sort logic. How bad
would it hurt to replace it all with std::sort() ?

bool compare(const Allrecords* left, const Allrecords* right)
{
return strcmp( left->Newirrecord.cu stomercode,
right->Newirrecord.cu stomercode));
}

Then,

std::sort(rec, rec+reccount, compare);

This is probably not the exact right code because I gave up on exactly
following your logic, but how far off is it?

Jul 22 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2116
by: SCS | last post by:
System: Windows 2003 Server PHP 5 Final IIS 6 Problem: Every time I run a PHP page I get "PHP has encountered an Access Violation at 017473CD" at the bottom of the page... But even worse, when I try to run a mysql/php page I get "Fatal error: Call
9
2841
by: Allen | last post by:
Hi all, I tried posting to one of the ms.win32 groups and haven't gotten a response yet. It may be my C++ that's at fault anyway so I'll try here too. I wrote a .dll that is misbehaving (access violation at startup) and I can't find the problem. I'm using load time linking and, when I try to step into program execution to find the...
0
2710
by: Steven Reddie | last post by:
In article <slrnbnj19j.av.juergen@monocerus.manannan.org>, Juergen Heinzl wrote: >In article <f93791bd.0309282133.650da850@posting.google.com>, Steven Reddie wrote: >> I understand that access violations aren't part of the standard C++ >> exception handling support. On Windows, a particular MSVC compiler >> option enables Microsoft's...
7
3124
by: Daniel | last post by:
I want to write a method to remove the last node of the linked list. But the error "Access Violation" exists and the error point to this method. What does it means by Access Violation and how can I debug it? Thanks void RemoveNode(StepNodePtr pList) { StepNodePtr preq, q; q = pList; preq = pList;
1
2031
by: Thomas Albrecht | last post by:
My application fails during initialization of the dlls with an ExecutionEngineException and a access violation in the MFC app. The structure of the program looks like: MFC app -> mixed DLL -> managed DLL (C#) Because the exception/access violation occures during startup none of my breakpoints are reached. I disabled the access to the...
0
1831
by: techie | last post by:
I have created an event sink in my ATL COM project. The event sink receives events from a C# component. There is no problem with receiving events but when my COM object is released I get an access violation - (MSCORWKS.DLL): 0xC0000005: Access Violation. At first I thought it could be due to my C++ code but after quite a lot of...
0
1389
by: techie | last post by:
I have created an event sink in my ATL COM project. The event sink receives events from a C# component. There is no problem with receving events but when my COM object is released I get an access violation - (MSCORWKS.DLL): 0xC0000005: Access Violation. Here's my event sink class: namespace { static const int EVENT_ID = 111;//any...
10
2084
by: Robert | last post by:
I am an attorney in a non-profit organization and a self-taught programmer. I'm trying to create a client db that will allow me to search for potential conflicts of interest based either on Social Security # or on Last Name. I've created two different tables with the following fields in each table: ClientInfo Client# (primary key) First...
2
4267
by: =?Utf-8?B?c29jYXRvYQ==?= | last post by:
Hi, I have a DLL in VC6, when a specific function is called it will spawns a few threads and then return. The threads stay running and inside one of these threads an event is created using the win32 CreateEvent() call: Code Snippet static HANDLE hReadyEvent;
39
4246
by: Martin | last post by:
I have an intranet-only site running in Windows XPPro, IIS 5.1, PHP 5.2.5. I have not used or changed this site for several months - the last time I worked with it, all was well. When I tried it just now, I am getting the subject error message (specifically: PHP has encountered an access violation at 00F76E21). The error is NOT occurring...
0
7693
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7916
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8117
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7660
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6275
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
932
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.