|
-
Jul 20th, 2008, 08:30 AM
#1
Thread Starter
Member
Real length of a char string?
The length of a character string is usually identified by the first null byte. But what if you had read a binary file? Files are filled with null bytes. I know fread returns the amount of bytes read, but is there another way?
So strlen("123456") returns 6;
strlen("123456\07"), that is 1,2,3,4,5,6,NULLBYTE,7, and that returns 6. Any otehr way?
Last edited by hellowonn; Jul 20th, 2008 at 08:46 AM.
-
Jul 20th, 2008, 10:14 PM
#2
Re: Real length of a char string?
If your main concern is binary files there are usually platform specific APIs for counting the length of files.. which are basically strlen that ignores null bytes.
You could probably find a function on the internet with little trouble that counts strings without looking for a null byte.
chem
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Jul 22nd, 2008, 06:34 AM
#3
Re: Real length of a char string?
So you mean basically the length of the file? Look up fseek() and ftell().
I don't live here any more.
-
Jul 22nd, 2008, 07:58 AM
#4
Thread Starter
Member
Re: Real length of a char string?
No, I just used that as an example.
-
Jul 22nd, 2008, 12:22 PM
#5
Re: Real length of a char string?
Then the answer to your question is implementation-specific and you'll have to do some research.
I don't live here any more.
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
|