Solved

Reading Blank Lines with Borland C++ Builder 3

Posted on 2000-02-16
22
472 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
  • 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
 

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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now