473,511 Members | 13,105 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What is wrong with my code? (strings)

79 New Member
Hello,

I have written a fairly complex parsing tool that is used to parse information from company documents. The program works very well, but in order to insure that all the data is copied properly, I had to remove some of the things that are not part of the data, but are simply headings. Here is what I mean:

Expand|Select|Wrap|Line Numbers
  1. *Heading
  2. <CODE1> = <COMMAND1>
  3. <CODE2> = <COMMAND2>
The program reads in each line, and separates <CODE1> from <COMMAND1> at the equals sign. the program then stores the <COMMAND1> in a CMapStringToString object with <CODE1> as the key. I have already mentioned that in other discussions.

Here is the problem: when retrieving <COMMAND1> directly below the heading, the code isn't simply <CODE1>, but all the stuff in the heading is part of it. What I mean is, if I want to get whatever is stored as <COMMAND2>, I would type:

Expand|Select|Wrap|Line Numbers
  1. CMapStringToStringObject["<CODE2>"]
But if I want to get <COMMAND1>, I would have to type:

Expand|Select|Wrap|Line Numbers
  1. CMapStringToStringObject["*Heading\n<CODE1>"]
So in order to solve this, I designed the program to delete the first digits of the <CODE> string if they are not equal to "<". This works, but when I output everything to the console, the headings disappear, as they have been deleted.

So here is what I put before the printing is done:

Expand|Select|Wrap|Line Numbers
  1.         int i = 0;
  2.  
  3.         BOOL newLine = false, text = false;
  4.  
  5.         std_string code , cmd, dummy;
  6.  
  7.         while (std::getline(input, code, input.widen('='))) {    //reads in characters until the '='
  8.  
  9.             std::getline(input,cmd);                            //reads in remaining characters in the line
  10.  
  11.             code.erase(code.begin() + (code.size()-1));            //erase last character, a whitespace
  12.             cmd.erase(cmd.begin());                                //erase first character, a whitespace
  13.  
  14.             while (code[0] != '<') {                            //checks if the first character of 'code' is not <
  15.  
  16.                 if (code[0] == '\n') {
  17.                     newLine = true;
  18.                 } else {
  19.                     text = true;
  20.                 }            
  21.  
  22.                 dummy[i] = code[0];
  23.                 code.erase(code.begin());
  24.                 i++;
  25.             }
  26.  
  27.             if (newLine) {                //checks if there has been a newline character preceding a 'code' in this iteration
  28.                 wcout << endl;            //if there is, a newline character is printed onto console and ofstream file
  29.                 output << endl;
  30.             }
  31.  
  32.             if (text) {                            //checks if there has been text preceding a 'code' in this iteration
  33.                 wcout << dummy << endl;            //if there is, the text is printed onto console and ofstream file
  34.                 output << dummy << endl;
  35.             }
  36.  
  37.             newLine = false;    //resets the value for newLine to false
  38.             text = false;
  39.             i = 0;
  40.  
  41.         }
Like I said, all other parts of the code work, except for this:

Expand|Select|Wrap|Line Numbers
  1.             while (code[0] != '<') {                            //checks if the first character of 'code' is not <
  2.  
  3.                 if (code[0] == '\n') {
  4.                     newLine = true;
  5.                 } else {
  6.                     text = true;
  7.                 }            
  8.  
  9.                 dummy[i] = code[0];
  10.                 code.erase(code.begin());
  11.                 i++;
  12.             }
According to the debugger, it crashes at the second iteration, when it reaches dummy[i] = code[0]
May 24 '07 #1
1 1510
xoinki
110 New Member
std_string code , cmd, dummy;

u have not declared dummy as an array and u r using it as an array..
it is crashing because of that reason i suppose..
Xoinki
May 25 '07 #2

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

Similar topics

5
3193
by: Lee Redeem | last post by:
Hi there I've created abd uploaded this basic PHP script: <html> <head> <title>PHP Test</title> </head> <body> <H1 align="center">
5
3662
by: Koen | last post by:
Hi all, I am experimenting with DAO. I wrote this sub to update one specific field of one specific row in one specific table. Nothing wrong with the SQL statement, but when I execute this I get...
8
1432
by: Polaris | last post by:
Hi Experts: The program creates Panels and inicilize them. When I run the code below, the program crashes (at the line commented below). Any help is appriciated. Thanks in Advance! Polaris ...
14
1787
by: howa | last post by:
void reverse_string(char *str) { if (str == NULL) return; char tmp; size_t len = strlen(str); size_t mid = (int) len / 2; for (size_t i = 0; i < mid; i++) {
1
1294
by: Robert Dufour | last post by:
If I use Dim Myconn as new sqlclient.connection Dim srvVer as string srvVer = MyConn.serverversion What should I get back as string if I was connected to sql server 2000 (standard full version)...
3
2211
by: canabatz | last post by:
im using paging on this query: i got this code that returning wrong results: (SELECT bid_price, count(*) as n from bidding_details where bid_id=$bid_id GROUP BY bid_price DESC HAVING n = 1 ) ...
3
7314
by: muddasirmunir | last post by:
I am trying to give the following Icon in my form in vb6. http://www.mediafire.com/?ymzgkgyi50j But , when I put this in my form I got error "Invalid Picutre" What wrong in it? How to add...
2
2380
by: Debbie Stevens | last post by:
What html code do I use to offer viewers of my webpage different text sizes?
0
7245
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,...
0
7427
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...
1
7085
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...
0
7512
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5069
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4741
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...
0
3214
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1577
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 ...
1
785
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.