Scrigroup - Documente si articole

Username / Parola inexistente      

Home Documente Upload Resurse Alte limbi doc  

AccessAdobe photoshopAlgoritmiAutocadBaze de dateCC sharp
CalculatoareCorel drawDot netExcelFox proFrontpageHardware
HtmlInternetJavaLinuxMatlabMs dosPascal
PhpPower pointRetele calculatoareSqlTutorialsWebdesignWindows

AspAutocadCDot netExcelFox proHtmlJava
LinuxMathcadPhotoshopPhpSqlVisual studioWindowsXml

An example performing input


+ Font mai mare | - Font mai mic


Trimite pe Messenger
Complete Programs in C
Directives - The null directive
An example performing input
Functions and Program Structure: Basics of Functions
Character handling - Strings, Untyped pointers
Keywords and identifiers
Recursion and argument passing - Call by value
Arrays, the & operator and function

An example performing input

It's useful to be able to perform input as well as to write programs that print out more or less interesting lists and tables. The simplest of the library routines (and the only one that we'll look at just now) is called getchar. It reads single characters from the program's input and returns an integer value. The value returned is a coded representation for that character and can be used to print the same character on the program output. It can also be compared against character constants or other characters that have been read, although the only test that makes sense is to see if both characters are the same. Comparing for greater or less than each other is not portable in general; there is no guarantee that 'a' is less than 'b', although on most common systems that would be the case. The only guarantee that the Standard makes is that the codes for through to will always be consecutive. Here is one example.

#include <stdio>
#include <stdlib.h>

Example 1.3

There are two interesting points in there. The first is to notice that at the end of each line of input read, the character represented by


(a character constant) will be seen. This just like the way that the same symbol results in a new line when printf prints it. The model of I/O used by C is not based on a line by line view of the world, but character by character instead; if you choose to think in a line-oriented way, then 'n' allows you to mark the end of each ‘line’. Second is the way that %c is used to output a character by printf, when it appears on the output as a character. Printing it with %d prints the same variable, but displays the integer value used by your program to represent the character.

If you try that program out, you may find that some systems do not pass characters one by one to a program, but make you type a whole line of input first. Then the whole line is made available as input, one character at a time. Beginners have been known to be confused: the program is started, they type some input, and nothing comes back. This behaviour is nothing to do with C; it depends on the computer and operating system in use.

Politica de confidentialitate



Vizualizari: 455
Importanta: rank

Comenteaza documentul:

Te rugam sa te autentifici sau sa iti faci cont pentru a putea comenta

Creaza cont nou

Termeni si conditii de utilizare | Contact
© SCRIGROUP 2021 . All rights reserved

Distribuie URL

Adauga cod HTML in site