C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28695
Number of posts: 94715

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Formatted & Unformatted Input / Output Posted by tokoG on 3 Apr 2006 at 5:00 AM
Hi

Studying thru the Input & Output functions.

Unformatted I/O functions...(such as getchar, fgets)
Formatted I/O functions.... (such as scanf, fscanf)

But,,, cant quite put my fingure on the differences between unformatted I/O and formatted I/O.


printf is formatted output. Is it because whatever you write between the
" " can be printed out (output) to the screen and that is refered as "being formatted"??

getchar is UNformatted input. Is it because it takes only one char each? (or did it take string also..?)

I am learning the 'details' of formatted and unformatted I/O but not quite sure about the most important thing, what is unformatted and formatted anyway?

Would anyone explain me or know a good web page to explain this..?

Thank you!
Report
Re: Formatted & Unformatted Input / Output Posted by Lundin on 3 Apr 2006 at 5:19 AM
: Hi
:
: Studying thru the Input & Output functions.
:
: Unformatted I/O functions...(such as getchar, fgets)
: Formatted I/O functions.... (such as scanf, fscanf)
:
: But,,, cant quite put my fingure on the differences between unformatted I/O and formatted I/O.
:
:
: printf is formatted output. Is it because whatever you write between the
: " " can be printed out (output) to the screen and that is refered as "being formatted"??
:
: getchar is UNformatted input. Is it because it takes only one char each? (or did it take string also..?)
:
: I am learning the 'details' of formatted and unformatted I/O but not quite sure about the most important thing, what is unformatted and formatted anyway?
:
: Would anyone explain me or know a good web page to explain this..?
:
: Thank you!
:


Yep, formatted I/O would probably be those functions accepting a format string: that is the first parameter in printf/scanf etc:

printf("%s %d I am the format string", str, i);
Report
Re: Formatted & Unformatted Input / Output Posted by tokoG on 3 Apr 2006 at 7:12 PM

:
:
: Yep, formatted I/O would probably be those functions accepting a format string: that is the first parameter in printf/scanf etc:
:
: printf("%s %d I am the format string", str, i);
:

Hi Lundin

Thanks doe the reply.

For example, looking the prototype of putc(int c, FILE* stream).
This is to Writes one btye to stream. I thought the stream is the string but not? It could be a character one by one? (the stream composed by characters, one by one, but NOT as a string)

Another example, gets(char* s). This is to Reads one line from standard input. Removed the ending newline character.
This is also a function for unformatted I/O but, it takes string. I thought strings were formatted I/O..?



Report
Re: Formatted & Unformatted Input / Output Posted by Lundin on 3 Apr 2006 at 11:23 PM
This message was edited by Lundin at 2006-4-3 23:23:23

:
: :
: :
: : Yep, formatted I/O would probably be those functions accepting a format string: that is the first parameter in printf/scanf etc:
: :
: : printf("%s %d I am the format string", str, i);
: :
:
: Hi Lundin
:
: Thanks doe the reply.
:
: For example, looking the prototype of putc(int c, FILE* stream).
: This is to Writes one btye to stream. I thought the stream is the string but not? It could be a character one by one? (the stream composed by characters, one by one, but NOT as a string)
:
: Another example, gets(char* s). This is to Reads one line from standard input. Removed the ending newline character.
: This is also a function for unformatted I/O but, it takes string. I thought strings were formatted I/O..?
:
:


putc() is for character, puts() for string. Same applies to getc() and gets(). Note that getc(stdin) is the same as getchar().

To write to the screen, use putc() like this: putc('A',stdout);
To write to a file, replace stdout with a FILE pointer.

With format string, I don't mean just any string, I mean a string containing things like %d %s etc. I assume that is what they mean with "formatted I/O". printf() will parse through the string you pass to it, replacing those symbols with values. puts() will only print "%d %s" on the screen.


Report
Re: Formatted & Unformatted Input / Output Posted by tsagld on 4 Apr 2006 at 3:24 AM
Formatted I/O means that presenting data in another form than it exists with.
For example, in memory I have the integer 321897, which is stored in four bytes (on a 32-bit machine) in binary.
Presenting this value to the user, on-screen for example, requires reformatting the four bytes to a readable 6-digit string:
int a=321897
printf("%d", a);


Another example is reformatting a string:
char* a="18";
printf("32%s97", a);


You see the use the %d and %s formatting characters. There are many more.
Hope this helps,

Greets,
Eric Goldstein
www.gvh-maatwerk.nl

Report
Re: Formatted & Unformatted Input / Output Posted by tokoG on 4 Apr 2006 at 4:09 AM
: Formatted I/O means that presenting data in another form than it exists with.
: For example, in memory I have the integer 321897, which is stored in four bytes (on a 32-bit machine) in binary.
: Presenting this value to the user, on-screen for example, requires reformatting the four bytes to a readable 6-digit string:
:
: int a=321897
: printf("%d", a);
: 

:
: Another example is reformatting a string:
:
: char* a="18";
: printf("32%s97", a);
: 

:
: You see the use the %d and %s formatting characters. There are many more.
: Hope this helps,
:

Thankd for this. Now I see why my tutorial book started this section wil explaining bits and bytes. I will print this post and paste on my tutorials. :)



Report
Re: Formatted & Unformatted Input / Output Posted by tokoG on 4 Apr 2006 at 6:54 PM

: : Another example is reformatting a string:
: :
: : char* a="18";
: : printf("32%s97", a);
: : 

: :

Btw, could you tell me why you used the pointer (*) for char a?
I mean, of course I tried (to execute) the code without but didn't work.. Because you can't use the digits on string between " "..? (I thought we could)

Thanks!
Report
Re: Formatted & Unformatted Input / Output Posted by Lundin on 4 Apr 2006 at 11:03 PM
:
: : : Another example is reformatting a string:
: : :
: : : char* a="18";
: : : printf("32%s97", a);
: : : 

: : :
:
: Btw, could you tell me why you used the pointer (*) for char a?
: I mean, of course I tried (to execute) the code without but didn't work.. Because you can't use the digits on string between " "..? (I thought we could)
:
: Thanks!
:

Because it is a string, not a char.
It is the same as writing char a[] = "18" or char a[3] = "18".
Report
Re: Formatted & Unformatted Input / Output Posted by tokoG on 4 Apr 2006 at 4:06 AM

: putc() is for character, puts() for string. Same applies to getc() and gets(). Note that getc(stdin) is the same as getchar().
:
: To write to the screen, use putc() like this: putc('A',stdout);
: To write to a file, replace stdout with a FILE pointer.
:
: With format string, I don't mean just any string, I mean a string containing things like %d %s etc. I assume that is what they mean with "formatted I/O". printf() will parse through the string you pass to it, replacing those symbols with values. puts() will only print "%d %s" on the screen.
:
:
:

The use of convension specifiers! (%d, and %s)
I was gonna ask this because I was just reading the chapter to explain more about what is formatted I/O!! Because my tutorial books explains UNformatted I/O first, I couldn't figure out what then formatted ones and what are the differences!!

Thanks, now with your explanation I understand.
:)




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.