473,320 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Crash on string compare

Hello, i'm having a problem where my program is crashing everytime it reachs a certain point. I get the error "test001.exe has encountered a problem and needs to close. we are sorry for the inconvenience".

Now, i've put cout << "display"; on every line to see where the crash occurs, and it happens with this statement
"if (strcmp(line.c_str(), "Importance: High")==0 )",
i've tried replacing it with "if (line == "Importance: High"){", yet it still crashes.

Im using visual studio 2008, but when compiled on my friends dev-c++ the code works fine. I can't switch IDE though. Im not sure what is going on here.

If I press debug I get the message "An unhandled win32 exception occurred in test001.exe [4612]. Then when I open the debugger I get "unhandled exception at 0x1049191c (msvcp90d.dll) in test001.exe:0xC0000005:Access violation reading location 0x00000018.

It then goes to the xstring file and goes to this line:
size_type __CLR_OR_THIS_CALL length() const
{ // return length of sequence
return ( Mysoze);
}

the following screenshot shows more detail:
http://img15.imageshack.us/my.php?image=errorrki.jpg

Code------
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

string checkpriority (string filenameandpath);

int main( )
{

string passtocheckpriorityfunction;
string priorityresult;

cout << "Enter the file path and name: ";
getline( cin, passtocheckpriorityfunction );

priorityresult = checkpriority(passtocheckpriorityfunction);

ofstream myoutputfile( "result.txt" );
myoutputfile << priorityresult;
myoutputfile.close();


return 0;
}



string checkpriority (string filenameandpath) { // my function

string line;

cout << "Opening file..." << std::endl;

cout << filenameandpath << std::endl;

fstream myinputfile;

myinputfile.open( filenameandpath.c_str(), ios::in | ios::out );

if (myinputfile.is_open())
{

while ( !(myinputfile.eof()) )
{
getline(myinputfile,line);

if (strcmp(line.c_str(), "Importance: High")==0 )
{
cout << "Found match." << std::endl;

return "Importance: 1.\n";
}
}

myinputfile.close();
}
}
Mar 16 '09 #1
2 3846
newb16
687 512MB
Really strange: according to your watch window, 'this' pointer during call to some member of 'line' is null. Did you try to debug it?
Mar 16 '09 #2
Try someting like this:

if (strcasecmp(line, "Importance: High") == 0) {
}
Mar 17 '09 #3

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

Similar topics

0
by: gael.pegliasco | last post by:
Hi, How are you dear and nice helper :) ? I'm trying to test xpath with this simple program : import xml.dom.minidom from xml.xpath.Context import Context import xml.xpath
10
by: dalbosco | last post by:
Hello, I am new to STL and I've written the following code which crash. Could anyone tell me why this code crash? Thanks by advance. -- J-F #include <iostream>
8
by: Adam Louis | last post by:
I would like help resolving this problem. I'm a novice who's been hired to query a hospital database and extract useful information, available to me only in a dynamically generated, downloadable...
3
by: Brad | last post by:
I have an aspx web page which initially displays fine. When I postback the resulting response back to the client output is causing InternetExplorer 6 to crash. I've disabled the server side code...
2
by: kevinding | last post by:
Hi All, We meet an evil condition for our project. Our project has 3 layers. A C# layer to do some business logic, and Managed C++ layer translate managed values to native ones or vice...
110
by: alf | last post by:
Hi, is it possible that due to OS crash or mysql itself crash or some e.g. SCSI failure to lose all the data stored in the table (let's say million of 1KB rows). In other words what is the worst...
16
by: linq936 | last post by:
Hi, It could be a very simple problem, but i can not see it... Here is the code: char* lower(char* str){ char* p = str; while ( *str ) { *str = tolower(*str); <=====crash! str++;
14
by: Mosfet | last post by:
Hi, what is the most efficient way of doing a case insensitive comparison ? I am trying to write a universal String class and I am stuck with the case insensitive part : TCHAR is a char in...
11
by: blunt | last post by:
trying to write a program to write the configuration files for a load of wireless access points. i've never been a good programmer and haven't done any for nearly a decade so have obviously made some...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.