Solved

Reading Blank Lines with Borland C++ Builder 3

Posted on 2000-02-16
22
482 Views
Last Modified: 2010-04-02
Hey, i need some help in reading over a blank line in borland C++ Builder. I've loded a file into a Memo box and am using 2 for loops to read individual chars to a string and look for a particular string. The only prolbem i have is that i cannot read over a blank line, when i try to do so i get an access violation. That particular line looks something like this
if(Memo1->Lines->Strings[x][y]!='\0')
The only prolbem with this is i still get an access violation when i try to run this. If anyone could help i'd be glad to help them out in any way possible.

Tom
0
Comment
Question by:Crovax
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 8
  • 3
22 Comments
 

Expert Comment

by:Stevex2
ID: 2527497
Try something similar to this.
Memo1->Lines->Strings[x].operator [](y) != '\0';


Also make sure your access violation is not coming from overshooting the lines/strings array.

0
 

Expert Comment

by:Stevex2
ID: 2527517
of course put the if brackets I forgot them :)
0
 
LVL 22

Expert Comment

by:nietod
ID: 2527613
It would help if we knew how lines and strings were declared. and how they work.  For example, if the blank line is represented using a NULL pointer, this would crash.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:Stevex2
ID: 2527643
Very true. If thats the case you could check those lines against the NULL before trying to read the chars.
0
 

Author Comment

by:Crovax
ID: 2527891
Well, the actual coding is
for (x=0;x<=Memo1->Lines->Count;x++)
        {

            for(y=1; y<=7;y++    )
            {
                if(Memo1->Lines->Strings[x][y]!='\0')
                string[y]=Memo1->Lines->Strings[x][y];
                else x+=0;
            }

            if(string[1]=='L' && string[2]=='O' && string[3]=='G' && string[4]=='O')
            {
                LineNum=x;
                break;
            }


        }
Once x becomes equil to 4 in the memo box there's a blank line (the actual file i'm reading is Msdos.sys and the 5th line of that file is blank on my computer). I tried Stevex2's method but to no avail...and the others i'm not quite sure i know what they mean (kinda new at this programming stuff).
0
 

Expert Comment

by:Stevex2
ID: 2528055
if(Memo1->Lines->Strings[x][y]!='\0')
               

this line add this check to it

if(Memo1->Lines->Strings[x] != NULL && Memo1->Lines->Strings[x][y]!='\0')
  string[y]=Memo1->Lines->Strings[x][y];
               
0
 
LVL 22

Expert Comment

by:nietod
ID: 2528057
but what is "Strings"!  How is it declared?  How is the data placed in it?
0
 

Expert Comment

by:Stevex2
ID: 2528062
That makes it check for a null first before continuing through to check for characters
0
 

Expert Comment

by:Stevex2
ID: 2528070
Ahh good check there Nietod.
0
 

Author Comment

by:Crovax
ID: 2528461
Nothin doin i guess. Tried
if(Memo1->Lines->Strings[x] != NULL && Memo1->Lines->Strings[x][y]!='\0')

but still got the access violation...it's a good idea checking for a NULL line before continuing, which is exactly what i was aiming for, but i'm not exactly sure how to do that. I was thinking alone the lines of checking to see if the first char in that line was null but i cant do that or the whole null line. I also though about loading the file into a list box and checking the individual lines there, but my limited knowledge of programming isnt doing me much good :(

Strings in Memo1->Lines->Strings is declaired by Borland C++ compiler and i'm not exactly how it declairs them. I think it's just a 2 dimensional array of chars. (i think so anywayz)

If it would help i could upload the entire Cpp file and give it to yall
0
 

Author Comment

by:Crovax
ID: 2528483
Adjusted points to 200
0
 

Author Comment

by:Crovax
ID: 2528484
Lemme give ya guys some more points for helpin me out here :)
0
 

Expert Comment

by:Stevex2
ID: 2528555
OKay one question real quick.  When you walk through it what line exactly does it bust out with the exception?
0
 

Expert Comment

by:Stevex2
ID: 2528559
And whats the x and y values at that time?
0
 
LVL 22

Expert Comment

by:nietod
ID: 2528583
CRTOVAX, LISTEN,

 WHAT IS "Strings"?

WE MUST KNOW HOW IT IS DECLARED  THE PROBLEM MAY VERY WELL BE THAT YOU'VE SIMPLY DECLARED IT WRONG BUT WE CAN'T TELL UNLESS YOU POST THE CODE USED TO DECLARE

HOW DO YOU FILL THE DATA INTO "Strings"?

WE MUST KNOW

WE CANNOT HELP YOU WITHOUT THIS SORT OF INFORMATION.
0
 

Accepted Solution

by:
Stevex2 earned 200 total points
ID: 2528678
I see whats happening.

i Think

The second variables string like nietod had commented might not be getting filled properly.  And yes we need to know how string is declared. did you declare it

char string[25]; or
CString string;

if(Memo1->Lines->String[x].GetLength > 4)//this is due to the string variables having the need for 4 filled slots.
{

for(y=1; y<=7;y++    )
            {
                if(Memo1->Lines->Strings[x][y]!='\0')
                string[y]=Memo1->Lines->Strings[x][y];
                else x+=0;
            }

            if(string[1]=='L' && string[2]=='O' && string[3]=='G' && string[4]=='O')
            {
                LineNum=x;
                break;
            }
}
0
 

Expert Comment

by:Stevex2
ID: 2528681
forgot the () on the GetLength
0
 

Author Comment

by:Crovax
ID: 2528688
Stevex, you are the MAN
0
 

Expert Comment

by:Stevex2
ID: 2528738
That fixed it right up?
0
 

Author Comment

by:Crovax
ID: 2528756
yep, actually, i was inspired by that comment, what i found was that it was actually skipping that blank line but sence y become equil to 7 and tried to check the 7th char of line 11 which happened to be only 6 chars long, it was causing an access violation. All the other lines (excluding the blank one which was skipped) were longer then 7 chars. I didnt need to search 7 chars, i only needed 4...LOGO. So simply by changing the y<=7 in the second for loop i solved the prolbem with a little inspiration. Thanks man, i owe ya. E-mail me if ya need anything (hawk002@bellsouth.net)
0
 

Author Comment

by:Crovax
ID: 2528881
yep, actually, i was inspired by that comment, what i found was that it was actually skipping that blank line but sence y become equil to 7 and tried to check the 7th char of line 11 which happened to be only 6 chars long, it was causing an access violation. All the other lines (excluding the blank one which was skipped) were longer then 7 chars. I didnt need to search 7 chars, i only needed 4...LOGO. So simply by changing the y<=7 in the second for loop i solved the prolbem with a little inspiration. Thanks man, i owe ya. E-mail me if ya need anything (hawk002@bellsouth.net)
0
 

Author Comment

by:Crovax
ID: 2529146
yep, actually, i was inspired by that comment, what i found was that it was actually skipping that blank line but sence y become equil to 7 and tried to check the 7th char of line 11 which happened to be only 6 chars long, it was causing an access violation. All the other lines (excluding the blank one which was skipped) were longer then 7 chars. I didnt need to search 7 chars, i only needed 4...LOGO. So simply by changing the y<=7 in the second for loop i solved the prolbem with a little inspiration. Thanks man, i owe ya. E-mail me if ya need anything (hawk002@bellsouth.net)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question