Posted by Computer Consultant on 1999-04-03
At 11:10 PM 4/3/99 +0200, you wrote:
>Computer Consultant wrote:
>> >* How do I get the size of a file in C?
>> There's a few ways. And there's a structure to get all information about a
>> file.
>> Here's one way to get file legnth, not sure if it's ansi:
>
>> Length = filelength(fileno(shit));
>where is this filelength function defined? according to your helppc file
>it's in io.h (/usr/include/sys/io.h) which does not define filelength()
>on my system. I'm using gcc under linux (and the proggy should run on a
>netBSD system then).
>
>What are the other ways to do this?
>
Ya, that might not be standard.
Try fstat()
>
>> Look in a book under file I/O.
>Downloaded a few tutorials and other stuff from the net. Among those C
>Programming by Steve Holmes (University of Strathclyde Computer
>Centre). It's quite usefull but it said nothing on filelength :(
>
>
>> >append a string to an existing one. (including new memallocation...) or
>> strcat appends, but you it won't do new memory allocation, use
malloc/realloc
>ok, thought of this. would have been too nice if there already was such
>a thing.
>
>
>
>> >* Has someone a function that replaces each occurence of given substring
>> >in a string by another string?
>
>> Something like this would be good (I just typed this in now so it's not all
>> that great but you get a general idea)
>> while(OldString[Index])
>> {
>> if(OldString[Index] == SearchString[0])
> <..>
>> Index++;
>> }
>
>thank you, I just wonder if there's nothing like the pos() function in
>pascal in C? on the other hand pos does exactly what you did.
Truthfully, I don't memorize the whole C library since mostly all of it
you can write yourself, most common functions I use a lot stay in my memory.
And, a lot of times writing them yourself makes faster code than the ones
in the library, and more robust depending.
>--
>Weasel mailto:palfrader@xxxxxxx.xxx
>Peter http://www.cosy.sbg.ac.at/~ppalfrad/
>------------------------------------------------------------
> We have full klingon console support just in case.
> -- Alan Cox on linux-kernel
>
>
>
+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=+
| http://www.nauticom.net/www/secret |
+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=+
3%
Previous post | Next post | Timeline | Home