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
13 2203
thank you so far, but i feel the sort is ok, i won't know until I can get the
sort file to work. The sort file does create a text file on the floppy disk,
but when I go to execute the program there is an access violation error
concerning the sort file.
Thanks again for your help, can someone run the program rthrough their own
compiler just to check.
The program is suppose to open a binary file (in this case validdata), and sort
the contents of validdata and then write this to sort_file.
if anyone is feel brave or a little bored can they actually write a program for
me that opens a text file and a binary file and get the contents of the binary
file to the sort_file.
Comments follow.
I see you didn't follow my earlier advice not to try to do too much at once.
Your post is full of code which does nothing like what you hope it does.
This isn't surprising, programming is hard and you are new at this.
There is a way to avoid wasting your time writing lots of code which will
just have to be thrown away. The way is to write small amounts of code at a
time (literally 3, 4, 5 lines at most), and get those lines working before
you write any more. This is how professionals work, although their
experience means that they can write code in bigger chunks than 3 - 5 lines.
The way to have you tearing your hair out is to write lots of code without
doing any testing at all.
Don't worry newbies never follow this advice. You'll find out the hard way.
"JasBascom" <ja*******@aol. com> wrote in message
news:20******** *************** ****@mb-m11.aol.com... 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++; }
}
This function will crash as soon as it is entered. The problem is the
uninitialised pointers str_ptr1 and str_ptr2. This is the same mistake you
made in main. More seriously this code performs nothing like a sort, not
even close, it should be thrown away.
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);
What is this? Why seek to one byte before then end of the file? What do you
think that achieves? reccount = sizeof(filesize )/sizeof(Allrecor ds);
This is wrong. Should be filesize not sizeof(filesize ). This is a good
example of where you are gonig wrong. Obviously you cannot go any further
until you have worked out the number of records in the file. Until you can
do this the rest of your program isn't going to work. So you should have
written the above code, and then STOPPED THERE! Tested your code and seen if
you calculated the number of records correctly. Then you can carry on and
write some more code. At the moment your code doesn't work, and you have no
idea of its the number of records that is wrong, or something completely
different.
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);
This seems a bit confused, are you trying to sort all the records or just
one record? I presume you are trying to sort all the records, but then why
is the sort_function call in a loop?
default:; };
};
return 0;
}
Seriously the best advice would be to throw this code away and take my
advice to write the program a little bit at a time. You are just heading for
weeks and weeks of frustration any other way.
john
"JasBascom" <ja*******@aol. com> wrote in message
news:20******** *************** ****@mb-m11.aol.com... thank you so far, but i feel the sort is ok, i won't know until I can get
the sort file to work.
That's the problem isn't it? Suppose you get the sort file to work, maybe
the changes you make as a result of that, will mean that you have to rewrite
the sort function.
For the record the sort function is not remotely right.
The sort file does create a text file on the floppy disk, but when I go to execute the program there is an access violation error concerning the sort file. Thanks again for your help, can someone run the program rthrough their own compiler just to check. The program is suppose to open a binary file (in this case validdata), and
sort the contents of validdata and then write this to sort_file. if anyone is feel brave or a little bored can they actually write a
program for me that opens a text file and a binary file and get the contents of the
binary file to the sort_file.
Something like this (untested, but please test it your self!)
ifstream validdata("myfi le", ios::in|ios::bi nary);
validdata.seekg (0, ios::end);
filesize = validdata.tellg ();
recount = filesize/sizeof(Allrecor ds);
rec = new Allrecords[reccount];
validdata.seekg (0, ios::beg);
validdata.read( rec, filesize);
validdata.close ();
john
On Fri, 20 Feb 2004 18:32:29 -0000 in comp.lang.c++, "John Harrison"
<jo************ *@hotmail.com> was alleged to have written: "JasBascom" <ja*******@aol. com> wrote in message news:20******* *************** *****@mb-m11.aol.com... thank you so far, but i feel the sort is ok, i won't know until I can get the sort file to work.
That's the problem isn't it? Suppose you get the sort file to work, maybe the changes you make as a result of that, will mean that you have to rewrite the sort function.
Ditto. Comment out the sort function and don't even worry about it
until the program reads and writes the file without sorting it. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
|
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 problem, I don't even get to the start of
WinMain before it throws the exception. The source files are...
|
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 Structured Exception Handling (SEH) in
C++
>> EH so that a catch (...) will catch an access violation. ...
|
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;
|
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 DLL step by step and
| |
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
investigation I don't think there is nothing wrong with it. The access
violation occurs after the destructor...
|
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 arbitary value
|
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 Name
Middle Name
Last Name
|
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;
|
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 on every page request (but it is on most of
them) and, when I get the error, simply pressing <F5to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |