| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | getc() |
> I'm trying to read a string into a buffer, and I have to find the > nul terminator to know where to stop. getc() is one way to do > this, one character at a time... a way you said was as fast as > fread() into a buffer, where I look for the character one at a > time in the buffer. You are WRONG. It's much quicker to read a > block from the file, and then process the block. I don't know why > this should be. How do they read from a file in a block? NP> A file read (at the lowest level) places one sector (512 bytes) NP> into a particular place in memory allocated for that purpose. This is what Paul said, but it doesn't work in practice. If I read characters using getc() one at a time, it is much slower than using fread() which reads to a buffer... and then run down the buffer. NP> If you know where it is (I've forgotten how to find out) then NP> access to the data is easy. (grin) Use fread(buffer, 512, 1, filename)... NP> IOW it reads a sector from the file regardless of whether your NP> program asks for 1 byte or a block. No, it doesn't. What you say is probably true, but every time I call getc() it must read the sector again, move the file pointer up one, and take the first character. Regards, Bob ___ Blue Wave/QWK v2.12 @EOT: ---* Origin: Precision Nonsense, Sydney (3:711/934.12) SEEN-BY: 711/808 934 712/610 @PATH: 711/934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.