• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 495
  • Last Modified:

Reading Blank Lines with Borland C++ Builder 3

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
Crovax
Asked:
Crovax
  • 11
  • 8
  • 3
1 Solution
 
Stevex2Commented:
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
 
Stevex2Commented:
of course put the if brackets I forgot them :)
0
 
nietodCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Stevex2Commented:
Very true. If thats the case you could check those lines against the NULL before trying to read the chars.
0
 
CrovaxAuthor Commented:
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
 
Stevex2Commented:
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
 
nietodCommented:
but what is "Strings"!  How is it declared?  How is the data placed in it?
0
 
Stevex2Commented:
That makes it check for a null first before continuing through to check for characters
0
 
Stevex2Commented:
Ahh good check there Nietod.
0
 
CrovaxAuthor Commented:
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
 
CrovaxAuthor Commented:
Adjusted points to 200
0
 
CrovaxAuthor Commented:
Lemme give ya guys some more points for helpin me out here :)
0
 
Stevex2Commented:
OKay one question real quick.  When you walk through it what line exactly does it bust out with the exception?
0
 
Stevex2Commented:
And whats the x and y values at that time?
0
 
nietodCommented:
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
 
Stevex2Commented:
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
 
Stevex2Commented:
forgot the () on the GetLength
0
 
CrovaxAuthor Commented:
Stevex, you are the MAN
0
 
Stevex2Commented:
That fixed it right up?
0
 
CrovaxAuthor Commented:
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
 
CrovaxAuthor Commented:
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
 
CrovaxAuthor Commented:
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

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 11
  • 8
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now