|
-
November 17th, 2001, 01:42 PM
#1
size of line grabbed from fgets() call
Hello again,
For those, who only wants to know my question,
read this, for those who wants to get more back
ground on it keep reading:
--[ QUESTION
is there a way of knowing the size of a line, in
a file, for example:
If file "victor.txt" has a line like this:
"victor12345"
I want to be able to know, that the specific line
has 11 bytes in it. Anyone?
Im coding an application that at some point will
need to open a file with reading attributes, and
read line by line and compare two string using a string search
algorithm, if the string inside the line grabbed
from fgets, exist inside a string that comes from
a user input.
So, i've placed a call like this on my code,
(consider that the file is already opened and can
be viewed with fp descriptor)
char line[300];
while(fgets(line, sizeof(line), fp) != NULL) {
searchalgorithm(line,outsidebuffer);
}
Now here come's my problem, when i do a call like
the fgets one i did above, it will put the content
of the line inside "line", however if line is < 300 bytes, then it will (by security measures, i think) fill up the restant of bytes with null chars, so looking from a program point of view,
if the string inside the file fp is: "seeweed",
with that fgets function what char line will hold is: "seeweed+293 NULL CHAR's", however if a user
types "seeweed" only, i will try to find:
"seeweed+293NULL chars" inside "seeweed", what
obviuslly doesnt exist...
So after this long story , here is my question,
is there a way of knowing the size of a line, in
a file, for example:
If file "victor.txt" has a line like this:
"victor12345"
I want to be able to know, that the specific line
has 11 bytes in it.
Anyone can help?
[]'z setuid
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|