Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

get, put, and putback

zeroscspotzeroscspot Posts: 40Member
Ive noticed with such things as get, put and putback that each of these work with char but doesnt say anything about int or double.

ive gotten the impression that files , both input and out put read characters only one at a time

Are files both input and output read only one character at a time?



Comments

  • shaolin007shaolin007 Posts: 1,018Member
    : Ive noticed with such things as get, put and putback that each of these work with char but doesnt say anything about int or double.
    :
    : ive gotten the impression that files , both input and out put read characters only one at a time
    :
    : Are files both input and output read only one character at a time?
    :
    :
    :
    :
    [green]
    No, there are functions that can take multiple strings of characters at one time. fgets() is a good one and is safe to use since it has a range check. Check it out as well as fputs(), fprintf(), fscanf(), and anyother f*() function.
    [/green]
  • dennisparkerdennisparker Posts: 478Member
    : Ive noticed with such things as get, put and putback that each of these work with char but doesnt say anything about int or double.
    :
    : ive gotten the impression that files , both input and out put read characters only one at a time
    :
    : Are files both input and output read only one character at a time?
    :
    :
    :
    :

    If you are wanting to do file I/O on data that includes multi_byte types like int and double, then I doubt that the character I/O routines that you mention are appropriate.

    In those cases you will need to use fread() and fwrite() where you explicitly set the number of bytes that you want to transfer. The files generated in this manner are binary files.

    Unlike the character based file I/O functions, binary file I/O by nature imposes a specific format (the one you set up). If you want to save a whole series of doubles, and sizeof(double) == 4, then the entire file must be written to and read from 4 bytes at a time.
Sign In or Register to comment.