Crovax
asked on
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
if(Memo1->Lines->Strings[x
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
of course put the if brackets I forgot them :)
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.
Very true. If thats the case you could check those lines against the NULL before trying to read the chars.
ASKER
Well, the actual coding is
for (x=0;x<=Memo1->Lines->Coun t;x++)
{
for(y=1; y<=7;y++ )
{
if(Memo1->Lines->Strings[x ][y]!='\0' )
string[y]=Memo1->Lines->St rings[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).
for (x=0;x<=Memo1->Lines->Coun
{
for(y=1; y<=7;y++ )
{
if(Memo1->Lines->Strings[x
string[y]=Memo1->Lines->St
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).
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->St rings[x][y ];
this line add this check to it
if(Memo1->Lines->Strings[x
string[y]=Memo1->Lines->St
but what is "Strings"! How is it declared? How is the data placed in it?
That makes it check for a null first before continuing through to check for characters
Ahh good check there Nietod.
ASKER
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
if(Memo1->Lines->Strings[x
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
ASKER
Adjusted points to 200
ASKER
Lemme give ya guys some more points for helpin me out here :)
OKay one question real quick. When you walk through it what line exactly does it bust out with the exception?
And whats the x and y values at that time?
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
forgot the () on the GetLength
ASKER
Stevex, you are the MAN
That fixed it right up?
ASKER
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)
ASKER
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)
ASKER
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)
Memo1->Lines->Strings[x].o
Also make sure your access violation is not coming from overshooting the lines/strings array.