Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > File handling in C

Reply
Thread Tools

File handling in C

 
 
PJ
Guest
Posts: n/a
 
      09-29-2005
Hi,

I have a file that contains some data. I want to write a function that
reads the file and return a string(char *) which contains the content
of file.(File can be of any size).

PJ

 
Reply With Quote
 
 
 
 
Mike Wahler
Guest
Posts: n/a
 
      09-29-2005

"PJ" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> Hi,
>
> I have a file that contains some data. I want to write a function that
> reads the file and return a string(char *) which contains the content
> of file.(File can be of any size).


So write it. If you get stuck, post your code and
ask specific questions. That's how to get help here.

If you're looking for someone to write the code for
you, try a 'help wanted' group.

-Mike


 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      09-29-2005


PJ wrote On 09/29/05 10:28,:
> Hi,
>
> I have a file that contains some data. I want to write a function that
> reads the file and return a string(char *) which contains the content
> of file.(File can be of any size).


Use fopen() to "connect" an input stream to your file.

Use malloc() to obtain a memory area to hold the
content.

Use getc() to read characters from the stream, one at
a time. As you read each character, store it in the next
byte of your memory area. If you receive more characters
than will fit, use realloc() to enlarge the area.

When getc() says there are no more characters, store
a '\0' to mark the end of the string. Remember that this
terminator takes space just like "real" characters; if
all the "real" characters exactly fill your memory area
you need one more byte for the '\0'.

Use fclose() to "disconnect" the stream from the file.

--
http://www.velocityreviews.com/forums/(E-Mail Removed)

 
Reply With Quote
 
Gregory Pietsch
Guest
Posts: n/a
 
      09-29-2005

PJ wrote:
> Hi,
>
> I have a file that contains some data. I want to write a function that
> reads the file and return a string(char *) which contains the content
> of file.(File can be of any size).
>
> PJ


This seems like another question with the same answer. Go get FreeDOS
Edlin (available at either ibiblio or alt.sources) and see how I did
it.

Gregory Pietsch

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
signal handling and (structured) exception handling Peter C++ 34 10-17-2009 10:03 AM
python list handling and Lisp list handling Mark Tarver Python 22 04-26-2009 09:36 PM
Is faster handling hexadecimal values than handling chars? IƱaki Baz Castillo Ruby 1 04-15-2008 09:04 AM
file handling in a server (.py) file using xmlrpc uwb Python 4 07-08-2005 07:55 PM
Handling large file upload Thomas Due ASP .Net 6 08-20-2003 12:06 PM



Advertisments