Is flag a keyword in C.
C programming: simple input and output
Probably no program can do without input and output. In C, however, the input / output is not part of the language itself. Rather, input and output exist as independent functions that are then integrated by the linker. You will get to know the most important input and output functions in this chapter.
We have already used this function in our previous programs. So it's time to take a closer look at them. The function has the following syntax:
But before we discuss, let's take a look at some basic concepts of functions. In a later chapter you will learn how to write a function yourself.
The two round brackets contain the parameter. In our example, the parameter is. The three dots after it indicate that the function can receive further parameters. The values passed to the function are known as Arguments. In our "Hello World" program, for example, we passed the argument "Hello World" to the function.
In addition, a function can have a Return value have. In this case the type of return value is. The type of return can be recognized by the keyword that precedes the function. You can recognize a function that does not return a value by the keyword.
The library function is used to output a character string on the standard output. Usually the standard output is the screen. The function has a pointer to a constant string as a transfer parameter. We'll see what the pointers are all about later. This means here that the function does not change the string. The number of characters output is supplied via the return value. If there was an error in the output, a negative value is returned.
Only strings are allowed as the first argument of. The compiler therefore issues a warning or an error when compiling the following line:
Because the quotation marks are missing, the compiler assumes that 55 is a number. If you enter 55 in quotation marks, the compiler interprets this as text. The compiler therefore does not issue an error for the following line:
Format elements of printf 
The function can also process several parameters, these then have to go through Commas separated from each other.
Output:3 plus 2 equals five.
The format elements introduced with the% symbol access the parameters separated by commas one after the other (the first to 3, the second to 2 and the string "five").
Be within Conversion sign (English conversion modifier) used for the other parameters. The correct type must be used here. The most important conversion symbols are:
|% d or% i||int|
|% c||single character|
|% e or% E||double in the format [-] d.ddd e ± dd or [-] d.ddd E ± dd|
|% f||double in the format [-] ddd.ddd|
|%O||Output int as an octal number|
|% p||the address of a pointer|
|% s||Output string|
|% u||unsigned int|
|% lu||long unsigned|
|% x or% X||Output int as a hexadecimal number|
Further formats and more detailed explanations can be found in the reference of this book.
After compiling and running the program, you will get the following output:Integer: 42 Double: 3,141000 characters: z String: abc 43 Decimal is in octal: 53 43 Decimal is in hexadecimal: 2b And finally we output the percent sign:%
In addition to the conversion character, a conversion specification can contain further elements for formatting. These are a maximum of:
- a Flag
- the Field width
- separated by a point the number of Decimal places (Length specification)
- and finally the conversion symbol itself
Immediately after the percent sign, the Flags (German designation) specified. They have the following meanings:
- (Minus): The text is justified to the left.
- (Plus): A sign is output even with a positive value.
- Space: A space is output if the value is positive.
- : The effect of the identifier depends on the format used: If a value is output as hexadecimal, then each value is preceded by 0x (unless the value is 0).
- : Padding is done with zeros instead of spaces when the field width is changed.
The following is an example that shows how the flags are used:
When the program is compiled and executed, we get the following output:Number 67: +67 Number 67: 67 Number 67: 0x43 Number 0: 0
Field width 
Behind the flag, the Field width (Eng. field width) can be specified. This means that the output is padded with the appropriate number of characters. Example:
When the program is compiled and executed, we get the following output:Output numbers right-aligned: 34, 343, 3343 Output numbers right-aligned, padded with 0 on the left: 00034, 00343, 03343 Output numbers left-aligned: 34, 343, 3343
In line 4 we used a 0 instead of the spaces, so that the field width is now padded with zeros.
By default, the output is right-justified. By placing the minus sign in front, the output can also be left-justified, as can be seen in line 5.
Decimal places 
After the field width, separated by a point, follows the accuracy. Otherwise, 6 decimal places are output by default. Of course, this information is only useful for floating point types, because all other types have no decimal places.
When the program has been compiled and executed, the following output appears on the screen:Total: 0.807
You have also already got to know the function. It has a similar syntax like:
The function reads in a value and saves it in the specified variables. But be careful: the function expects the address of the variable. Therefore the following function call leads to a error:
In contrast, the following is correct:
With the Address operator & you get the address of a variable. You can also have this displayed:
If you compile the program and run it, you get e.g. the following output:Address of x: 0022FF74 Contents of the memory cell: 5
The output of the address may vary with you. It is even possible that this information changes each time the program is restarted. This depends on where the program (from the operating system) is loaded into memory.
We will deal with addresses in more detail in the Pointers chapter.
The following placeholders can be used for to ensure that the entered value is converted into the "correct" format:
|% d||signed integer as decimal value|
|% i||signed integer as decimal, |
Hexadecimal or octal value
|% e,% f,% g||Floating point number|
|%O||Read int as an octal number|
|% s||Read in character string|
|% x||Hexadecimal value|
|%%||recognizes the percent sign|
getchar and putchar 
The function returns the next character from the standard input stream. A electricity Stream is an ordered sequence of characters that a device has as a destination or source. In the case of, that device is the standard input - usually the keyboard. However, the stream can also have other sources or destinations: If we later deal with saving and loading files, then the destination and source of the stream will be a file.
The following example reads a character from standard input and outputs it. You may have to press
If we enter "hello" on the keyboard, we first get the first character (ie the "h") by calling up. Calling up again gives us the next character, and so on. The function is, so to speak, the reverse of: It returns a single character c on standard output. Usually the standard output is the monitor.
Admittedly, there is little point in using here, unless you intend to read only the first character of an entry. Often used with bows. We will get to know an example of this later.
Escape sequences 
Control characters benefit from a special representation in C. Control characters are characters that are not directly visible on the screen, but rather fulfill a specific task, such as starting a new line, displaying the tab character or outputting a warning signal. For example, leads
not to the result that a new line is started after the word "text", but the program outputs after compilation:This is text without a line break
A new line is only started if there is a in the corresponding place. The following list shows all escape sequences available in C:
- (new line) = moves the cursor to the starting position of the next line.
- (horizontal tab) = Moves the tabulator to the next horizontal tabulator position. If the cursor has already reached the last tabulator position, then the behavior is unspecified (provided a last tabulator position exists).
- (alert) = issues an audible or visual alarm without changing the position of the cursor
- (backspace) = Resets the cursor one character. If the cursor is already at the beginning of the line, the behavior is unspecified.
- (carriage return) = Places the cursor at the beginning of the line
- (form feed) = Places the cursor on the start position of the next page.
- (vertical tab) = Moves the cursor to the next vertical tab position. If the cursor has already reached the last tab position, then the behavior is unspecified (if one exists).
- "is issued
- 'is output
- ? is issued
- \ is output
- is the end marker of a character string
Each escape sequence symbolizes a character on an implementation and can be stored in a variable of the type.
Generates the following output on the screen:The line break occurs with the escape sequence \ n start of record a carriage return is generated with \ r: The following output demonstrates the function of \ b 13579 This is readable
- Who is Bob Marley's brother
- How is Ronaldo very good
- Why are excursions good for students
- How are you
- Did privatization work in the UK
- What uses microwaves
- How does mouse deer taste
- Is Suga the father of BTS
- How would Batman deal with Wilson Fisk
- Who made you feel great today
- What have the religions done to stop wars?
- Landau music is a real thing
- Why are no more churches built with steeples?
- What color is the letter a
- Is the hydrogenation an addition reaction
- Which state capital name begins with DE
- Have you ever got drunk in Germany?
- Why is phishing legal at all?
- What are the symptoms of mantra siddhi
- Is there a pranayama to control hunger
- What does the word sere
- Will yellow leaves ever turn green again?
- Why do you support feminism
- Is shopping an economic activity?