Coder's Guild Mailing List

Re: some C questions

Posted by Weasel on 1999-04-03

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?


> 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.
-- 
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