473,769 Members | 4,470 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access Violation----Why is that?

stealwings
34 New Member
I have implemented a binary search and some other functions to my code, when I compile it, it gives me no error, but when I run it, it gives me an Access violation, why? Can some one explain me plz. Thanks in advance.
Expand|Select|Wrap|Line Numbers
  1. // SpanishBreakPredict.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. using namespace std;
  7. #include <fstream>
  8. using std::ifstream;
  9. using std::ofstream;
  10. #include <stdio.h>
  11. #include <cstdlib>
  12. #include <string>
  13. #include <stdlib.h>
  14. #include <iomanip>
  15. #include <vector>
  16. #define MAXLENGTH 1000
  17.  
  18.  
  19. int wmain(int argc, wchar_t * argv[], wchar_t *envp[])
  20. {
  21.     char WordCount[MAXLENGTH];        //Temp array to save input file words for lenght calculation
  22.     char MyWord[MAXLENGTH];            //Temp array to save input file words.
  23.     char MyStandard[MAXLENGTH];        //Temp array to save the standard words list
  24. //    vector<string> MyWords;            // Vector to hold input file.
  25. //    vector<string> Standard;        // Vector to hold Text-normalization-phrases
  26.     ifstream CountStandard;
  27.     ifstream CountInput;
  28.     ifstream ReadWord;
  29.     ifstream ReadStandard;
  30.     ofstream WriteWord;
  31.  
  32. /**********************To get number of characters of each line****************************/
  33.     int StandardSize=0;
  34.     CountStandard.open("Standard.txt");
  35.     while(!CountStandard.eof()&&CountStandard.getline(WordCount, MAXLENGTH))
  36.     {
  37.         StandardSize++;
  38.     }
  39. //    cout<<StandardSize<<endl;
  40.     CountStandard.close();
  41.     vector<string> Standard(StandardSize);
  42.     int InputSize=0;
  43.     CountInput.open("file.txt");
  44.     while(!CountInput.eof()&&CountInput>>WordCount)//CountInput.getline(WordCount, MAXLENGTH))
  45.     {
  46.         InputSize++;
  47.     }
  48.     cout<<InputSize<<endl;
  49.     vector<string> MyWords(InputSize);
  50.  
  51. /**************************************************************************************/
  52.     WriteWord.open("file.dat",ios::app);
  53.     if(!WriteWord.is_open())
  54.     {
  55.         cerr<<"couldn't create file"<<endl;
  56.         exit(1);
  57.     }
  58.     ReadStandard.open("Standard.txt");    
  59.     if (!ReadStandard)
  60.     {
  61.         cerr<<"Standard text file not found."<<endl;    
  62.         exit (1);
  63.     }
  64.  
  65.  
  66.     while(!ReadStandard.eof())                        //read the file till reaches the end.
  67.     {
  68.  
  69.         ReadStandard.getline(MyStandard,MAXLENGTH);      // read a line from the file.
  70.                                                      //    (one line is a phrase)
  71.         Standard.push_back(MyStandard);    //push the phrase into the vector "Standard";
  72.  
  73.     }                                                //read standard words over
  74.     /*for(unsigned i=0; i<Standard.size();i++)
  75.         {
  76.             cout<<Standard[i]<<endl;
  77.         }*/
  78.     ReadStandard.close();//close the file handle;
  79.  
  80.  
  81.     ReadWord.open("file.txt");
  82.     if (!ReadWord)
  83.     {
  84.         cerr<<"input file not found please ensure it exist."<<endl;
  85.         exit (1);
  86.     }
  87.  
  88.  
  89.     while(ReadWord>>MyWord)
  90.     {
  91.     //    cout<<MyWord<<endl;    
  92.     //    ReadWord>>MyWord;
  93.     //    ReadWord.getline(MyWord,MAXLENGTH);
  94.         MyWords.push_back(MyWord);    
  95.     }
  96.  
  97. /*******************************To print holding words of vector**********************/
  98. /*    for(int i=0; i<MyWords.size(); i++)
  99.     {
  100.         cout<<MyWords[i]<<endl;
  101.     }*/
  102. /**************************************************************************************/
  103.     ReadWord.close();
  104.     WriteWord.close();
  105.  
  106. /**************************************************************************************/
  107. /*                    SEARCH AND COMPARE, THEN REPLACE IF MATCH IS TRUE.                */
  108. /*                        Note: This part does a linear search                          */
  109. /**************************************************************************************/
  110. /*    for(unsigned i=0;i<Standard.size();i++) 
  111.     {
  112.  
  113.         for(unsigned j=0;j<MyWords.size();j++)  //each MyWords compare to the Standard 
  114.                                                 //and see if it is in the standard vector
  115.         {
  116.             string::size_type FoundAt=MyWords[i].find(Standard[j]);
  117.             while( string::npos != FoundAt )
  118.                 {
  119.                     MyWords[i].replace( FoundAt, Standard[j].length(),Standard[j]+"/");
  120.                     //cout<< MyWords[i]<< endl;
  121.                     FoundAt = MyWords[i].find( Standard[j], FoundAt + Standard[j].length() );
  122.                 }
  123.  
  124.             //if(MyWords[i]==Standard[j])            // if it equal to one of the words in the standard vector 
  125.             //    MyWords[i]=MyWords[i]+"/";            // add the slash to the end;
  126.         }
  127.  
  128.     }*/
  129.  
  130.  
  131. /*********************************************************************************************/
  132. /*                                    BinarySearch                                              */
  133. /*********************************************************************************************/
  134. int first=0, last, mid;
  135. while(Standard[first]<=Standard[last])
  136. {
  137.     Standard[mid]=Standard[(first+last)/2];
  138.     for (int i=0; i<MyWords.size(); i++)
  139.     {
  140.         if(MyWords[i]<Standard[mid].substr())
  141.             first=mid+1;        
  142.  
  143.     }
  144. }
  145. /***********************************Create output file****************************************/
  146. /*    for(unsigned j=0;j<MyWords.size();j++)        // for each word in MyWords vector  
  147.     {
  148.         WriteWord<<MyWords[j]<<endl;            // write it to the destination file
  149.     }
  150.     WriteWord.flush();                            // flush the memory to ensure all is written to the file
  151.     WriteWord.close();    */                        // close the write file handls
  152.     return 0;
  153. }
  154.  
THAT IS MY CODE AND THIS IS THE PART THAT IS GIVING ME TROUBLE
Expand|Select|Wrap|Line Numbers
  1. int first=0, last, mid;
  2. while(Standard[first]<=Standard[last])
  3. {
  4.     Standard[mid]=Standard[(first+last)/2];
  5.     for (int i=0; i<MyWords.size(); i++)
  6.     {
  7.         if(MyWords[i]<Standard[mid].substr())
  8.             first=mid+1;        
  9.  
  10.     }
  11. }
Apr 10 '07 #1
1 1537
stealwings
34 New Member
Sorry for the trouble, I already realized that it was a logical problem, it is solved, but I got this new problem, I have the part of the code as follow:
Expand|Select|Wrap|Line Numbers
  1. int first=0;
  2. int last= StandardSize-1;
  3. int mid=(first+last)/2;
  4. //cout<<MyWords.size()<<endl;
  5.     for (int i=0; i<MyWords.size();i++)
  6.     {
  7.         while(first<=last)
  8.         {
  9.             if(MyWords[i]>Standard[mid].substr())
  10.                 first=mid+1;
  11.             else if(MyWords[i]<Standard[mid].substr())
  12.                 last=mid-1;
  13.             else 
  14.                 cout<<Standard[mid]<<endl;
  15.         }
  16.         cout<<"Not found"<<endl;
  17.         return -1; 
  18.     }
  19.  
it gives me an infinite loop of blank spaces, why?
Apr 10 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
1264
by: Torsten Mohr | last post by:
Hi, in the documentation and the examples that describe how to make the members of a new type accessible it says that i need to use the getattrfunc and setattrfunc if i want to access members that are an array. typedef struct { PyObject_HEAD unsigned char d;
6
2070
by: jameshamilton777 | last post by:
I want to make my website properly accessible. I want to assign keys that navigate to a different page when pressed. I've looked into the accesskey attribute, but under IE that involves pressing the ALT key with the accelerator, and then pressing return. Is there a way that you can define an access key to just follow a link, without pressing ALT and without having to press RETURN?
1
1864
by: John Baker | last post by:
HI: Does anyone know a good manual or web site that addresses the development of applications using the Data Access Capability (HTM) in Access. I need to have something on a web site that, at minimum, feeds controlled data to an Access data base, and have no idea how to approach it. One key is that we must ensure that the data fed to the data base is consistent with some table contents ON the data base. This would typically be a lookup...
1
3420
by: Zvonko Tusek | last post by:
Is there a way to use access database on web host (I have a web hosting account) in visual basic. I want to make Visual basic client applications that connect to internet and work with access database on some web server. Can it be done? Tnx.
2
1247
by: freddy | last post by:
How can I connect to a access db that links to an excel spreadsheet and display the data in a datagrid
4
1132
by: THY | last post by:
Hi, I have create a connection to an access database, but before I close the connection, another user cannot run the web application correctly, I got the error Operation is not allowed when the object is open. is it the problem of my connection string ? thanks
0
1277
by: F I S H | last post by:
The site I am going to build has roughly 1000 html, php, asp, mp3, pdf, swf, doc. jpg, txt files etc....... I put them in 100 different folders. 200 users will be given access to 10 folders weekly. The folders that each user can access is in different combination and the combination change every week. I have read a lot on google about user access management, web access management, .htaccess access management but still can't find an...
2
2309
by: k-man | last post by:
Hi: I have an MS Access query for a table called MyTable. One of my fields in the query is a custom field that looks like "MyField: = MyFunction(ID)" where ID is a field in MyTable. I have ASP code and I can use it to read the query OK when "MyField" is not part of the query. If I add in MyField and then run my ASP code to try to read all the query fields, I get an error message on my web browser which says something to the effect...
6
4968
by: adversus | last post by:
Good afternoon folks: I am maintaining an Access application (in the form of a compiled ADP project, *.ade) that currently gets installed on client machines via a Windows VBScript. Right now when I push an update, I compile the project into the install folder on the network and Email all my users with the script attached. The users open the script and it installs a local copy from the network onto their desktop. Now, I'm curious if there...
1
1396
by: ken estes | last post by:
Have an older access program that I loaded to a mass storage device to upload into my laptop (Vista). When I try to initiate the Access program a display comes up saying I need to reformat the older program. Any advice on how to do so?
0
9591
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10225
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10053
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10001
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,...
0
6676
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();...
0
5312
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...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3969
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
3
2816
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.