Table of Contents
Example
Output
Home Backend Development C++ In C language, reading and writing characters refers to reading and writing character data through input and output functions.

In C language, reading and writing characters refers to reading and writing character data through input and output functions.

Sep 23, 2023 am 08:33 AM
input function Output function character data

In C language, reading and writing characters refers to reading and writing character data through input and output functions.

In the C programming language, the functions for reading and writing characters are as follows −

  • The simplest console input and output function is getche (), which reads a character from the keyboard, and putchar(), which prints a character to the screen.

  • The getche() function waits until a key is pressed and returns its value. The pressed keys are also automatically displayed on the screen.

  • The putchar() function writes its character parameters to the screen at the current cursor position.

  • The declarations of getche() and putchar() are as follows −

int getche (void);
int putchar (int c);
Copy after login
  • getche() and putchar() The header file is in CONIO.H.

Example

Below is an example that reads characters from the keyboard and prints them with reverse case. This means that uppercase letters print as lowercase letters and lowercase letters print as uppercase letters.

When you type a period, the program stops running. The islower() library function requires the header file CTYPE.H. This function returns true if its parameter is a lowercase letter, otherwise it returns false.

The following is an example of a C program reading and writing characters :

# include <stdio.h>
# include <conio.h>
# include <ctype.h>
main(void){
   char ch;
   printf (&ldquo;enter chars, enter a period to stop</p><p>&rdquo;);
   do{
      ch = getche ();
      if ( islower (ch) )
         putchar (toupper (ch));
      else
         putchar (tolower (ch));
   } while (ch! = &lsquo;.&rsquo;); /* use a period to stop */
   return 0;
}
Copy after login

Output

When the above program is executed, it produces the following results −

enter chars, enter a period to stop
tTuUtToOrRiIaAlLsS..
Copy after login

There are two important getche() variants as follows −

The first variant is as follows −

  • getchar( ) is that it buffers the input until a carriage return is entered.

  • The getchar() function uses the STDIO.H header file.

The second variant is as follows −

  • The second more useful variant of getche() is getch(), which The operation is exactly the same as getche(), except that the characters you enter will not be displayed on the screen. It uses the CONIO.H header file.

The above is the detailed content of In C language, reading and writing characters refers to reading and writing character data through input and output functions.. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Correct way to use scanf function in C language Correct way to use scanf function in C language Feb 19, 2024 pm 06:04 PM

How to correctly use the scanf function in C language Introduction: In C language, the scanf function is one of the commonly used input functions, which allows users to input data from the keyboard. However, due to some subtle differences in some features and usage of the scanf function, it may easily cause some problems. This article will introduce how to use the scanf function correctly and related precautions, and attach specific code examples. 1. The basic use of the scanf function: The basic use of the scanf function is very simple. It uses format words

How to optimize the efficiency of Go language input functions in practice How to optimize the efficiency of Go language input functions in practice Mar 27, 2024 pm 03:00 PM

Title: How to optimize the efficiency of Go language input functions in practice. In daily Go language development work, the efficiency of input functions often affects the performance of the entire program. This article will introduce how to optimize the efficiency of the Go language input function in practice, and explain the optimization method through specific code examples. Choose the appropriate input method First, you need to choose the appropriate input method according to actual needs. Normally, the most common input method in the Go language is to obtain data through command line parameters or standard input. When determining input methods, you need to consider the data

In C language, reading and writing characters refers to reading and writing character data through input and output functions. In C language, reading and writing characters refers to reading and writing character data through input and output functions. Sep 23, 2023 am 08:33 AM

In the C programming language, the functions for reading and writing characters are as follows − The simplest console input and output functions are getche(), which reads a character from the keyboard, and putchar(), which prints a character to the screen. . The getche() function waits until a key is pressed and returns its value. The pressed keys are also automatically displayed on the screen. The putchar() function writes its character argument to the screen at the current cursor position. The declarations of getche() and putchar() are as follows −intgetche(void);intputchar(intc);getche() and putchar(

What are the input functions in C language? What are the input functions in C language? Sep 01, 2020 am 09:27 AM

The input functions of C language include: 1. scanf() function, which reads formatted input from standard input stdin; 2. getchar() function, which obtains a character from standard input stdin; 3. gets() function, which reads formatted input from standard input stdin. Read a line; 4. The getch() function reads a string from the stdin stream and stops when a newline character or EOF is received.

What are the input functions in C language? What are the input functions in C language? Oct 11, 2023 am 11:41 AM

C language input functions include scanf function, getchar function, gets function, fgets function, scanf_s function, etc. Detailed introduction: 1. The scanf function is used to read data from the standard input stream. It can convert the input data into the corresponding type according to the specified format string and store it in the specified variable; 2. getchar function , used to read a character from the standard input stream, it will wait for the user to input a character, and return the ASCII code value of the character; 3. gets function, etc.

Learn the basics of Go language input functions from scratch Learn the basics of Go language input functions from scratch Mar 28, 2024 am 08:12 AM

Learn the basics of Go language input functions from scratch. Go language is a statically typed, compiled, and concurrent programming language developed by Google. It has concise syntax, efficient concurrency model and excellent performance, so it is favored by developers. In the process of learning Go language, understanding input functions is one of the most important basic knowledge. This article will start from scratch, introduce the basic knowledge of Go language input functions, and give specific code examples. 1.fmt package In the Go language, the fmt package is used to format input and

fscanf() function in PHP fscanf() function in PHP Sep 07, 2023 pm 04:29 PM

Thefscanf()functionparsesinputfromanopenfileaccordingtoaspecifiedformat.Itreturnsthevaluesparsedasanarray,ifonlytwoparameterswerepassed.Syntaxfscanf(file_pointer,format,mixed)Parametersfile_pointer−Afilesystempointerresourcecreatedusingfope

Detailed explanation of Go language input function and application examples Detailed explanation of Go language input function and application examples Mar 27, 2024 pm 01:12 PM

Detailed explanation of Go language input functions and application examples. Go language is a modern programming language with high development efficiency and easy to learn. Its standard library provides a wealth of input functions to facilitate developers to process input data. This article will introduce in detail the commonly used input functions and practical application examples in the Go language to help readers better understand and apply these functions. 1. Scan function in fmt package The fmt package of Go language provides a series of functions for formatting input and output, among which the most commonly used input function is the Scan function. S

See all articles