file reading...etc

E

ericunfuk

Hi, all

I'm very new to C and have a few basic questions:
I have an image file pic.tif, I want to read this image but only, say,
2KB per time and possibily I'm going to store this 2KB in an Array or
something then I will do something to this 2KB, then I will read
another 2KB. My question is:

Which function in C allows me to read a file by specifying the amount
of data to readin each time?

How many bytes are occupied by a "char" in C?


Thanks for any help you could provide.

Eric
 
E

Eric Sosman

ericunfuk wrote On 03/02/07 14:46,:
Hi, all

I'm very new to C and have a few basic questions:
I have an image file pic.tif, I want to read this image but only, say,
2KB per time and possibily I'm going to store this 2KB in an Array or
something then I will do something to this 2KB, then I will read
another 2KB. My question is:

Which function in C allows me to read a file by specifying the amount
of data to readin each time?

fread(), or getc() in a loop. See also Question 12.37
in the comp.lang.c Frequently Asked Questions (FAQ) list at

http://www.c-faq.com/
How many bytes are occupied by a "char" in C?

One, but the answer is tautological: C uses the word
"byte" to mean "the amount of memory occupied by one `char',
whatever that might be." (If you have a copy of "The Devil's
Dictionary" at hand, look up the two words "magnet" and
"magnetism.")

On most machines you're likely to encounter a `char'
has eight bits, making C's "byte" the same as everyone
else's "byte." There are, however, some exotic systems
that use 32-bit `char', and perhaps other widths can also
be found. On such systems, C's "byte" means something
different from the common parlance "byte."
 
S

santosh

ericunfuk said:
Hi, all

I'm very new to C and have a few basic questions:
I have an image file pic.tif, I want to read this image but only, say,
2KB per time and possibily I'm going to store this 2KB in an Array or
something then I will do something to this 2KB, then I will read
another 2KB. My question is:

Which function in C allows me to read a file by specifying the amount
of data to readin each time?

How many bytes are occupied by a "char" in C?


Thanks for any help you could provide.

In C, a char object is by definition one byte in size. That byte may
or may not be of eight bits, (though that's the most common one).

You can use either fgetc or fread in a loop to read in the required
amount of bytes.
 
C

CBFalconer

ericunfuk said:
.... snip ...

Which function in C allows me to read a file by specifying the
amount of data to readin each time?
fread.


How many bytes are occupied by a "char" in C?

One, by definition.

All this (and more) is available by reading your C book. Even if
it is among the worst such as bullSchildt.
 
S

SM Ryan

# Hi, all
#
# I'm very new to C and have a few basic questions:
# I have an image file pic.tif, I want to read this image but only, say,
# 2KB per time and possibily I'm going to store this 2KB in an Array or
# something then I will do something to this 2KB, then I will read
# another 2KB. My question is:
#
# Which function in C allows me to read a file by specifying the amount
# of data to readin each time?

fread and fwrite in stdio.h. You can read or write up to
a specified maximum number of elements, and they return
how many elements were actually read or written. Outside
of stdio.h there may be additional functions like read
and write. You may have to open the file in binary mode.

# How many bytes are occupied by a "char" in C?

A char is a byte; on any system you're likely to use, a
byte is an octet, or 8 bits, so that char, byte, octet,
and eight-bit element are all the same thing. A character
is no longer always exactly a char, sometimes multiple
bytes, but unless you're doing text processing, don't
worry about that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top