Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

why getchar() in C has return type int while we are reading

Status
Not open for further replies.

saurabh_embedded

Newbie level 4
Joined
Sep 23, 2005
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,323
hi friends,

why read and write operations in FILE is done with int, but atually we are reading char from the file.thus wasting 3 bytes(in linux)/one byte(inTC) in reading one byte data.

thanks,
 

The reason is that getchar() needs to report some abnorml state. For example, read error or end of file (EOF = -1). In this case the returned value is not 0~255. It is not possible to represent such cases with char type.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top