answersLogoWhite

0


Best Answer

The getchar() function gets a single character from stdin.

Here is a very basic example:

#include <stdio.h>

int main() {

char ch;

do {

ch = getchar();

putchar(ch);

} while (ch != ';');

return 0;

}

It reads from data you input and prints it again of the screen after you press key. It works until it reaches ";" symbol.

The getchar() function is equivalent to getc(stdin).

User Avatar

Wiki User

13y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

10y ago

The getchar function is a C function which returns the next character from stdin.

char c;

c=getchar();

The C++ equivalent would be:

char c;

std::cin>>c;

The get function has several overloads that allow the programmer to either fetch a single character, a C-string or a stream buffer from an input stream as unformatted input. Fetching a single character with get is similar to the C function, getchar, but returns an int rather than a char. You can also return the char through an output argument (the stream is returned by reference instead).

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the purpose of a getchar function?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Which function enables to receive single character input?

getchar();


How Can We Solve The Limitation Of Getchar And Scan Function?

Getchar:-Reading a single character can be done by using the function getchar.Syntax:- variable_name = getchar ( );Variable_name is a valid 'c' name that has been declared as char type. When this statement is encountered, the computer waits until a key is pressed and then assigns this character as a value to getchar function. Since getchar is used on the right hand side of an assignment statement, the character value of getchar is in turn assigned to the variable_name on the left. The getchar function may be called successively to read the characters contained in a line of text. Getchar accepts space character.Scanf ("control strings",arg1, arg2, &acirc;&euro;&brvbar;&acirc;&euro;&brvbar;&acirc;&euro;&brvbar;&acirc;&euro;&brvbar; argn);The control string specifies the field format in which the data is to be entered and the arguments arg 1, arg 2, arg n specify the address of locations where the data is stored. Scanf does not accept space character.


How is the getchar function used in a C program?

The getchar() is used in 'C' programming language because it can read the character from the Standard input(i.e..from the user keyboard),and converts in to the ASCII value.


What is function get in C programming?

There is no 'get' in the standard libraries, but for 'getc', 'getch', 'getchar', 'fgetc' etc you can find useful information in the help/manual.


What is the use of getchar?

gets()Reads characters from stdin and stores them as a string into str until a newline character ('\n') or the End-of-File is reached.The ending newline character ('\n') is not included in the string.getchar()Returns the next character from the standard input (stdin).It is equivalent to getc with stdin as its argument. === ===

Related questions

Which function enables to receive single character input?

getchar();


How Can We Solve The Limitation Of Getchar And Scan Function?

Getchar:-Reading a single character can be done by using the function getchar.Syntax:- variable_name = getchar ( );Variable_name is a valid 'c' name that has been declared as char type. When this statement is encountered, the computer waits until a key is pressed and then assigns this character as a value to getchar function. Since getchar is used on the right hand side of an assignment statement, the character value of getchar is in turn assigned to the variable_name on the left. The getchar function may be called successively to read the characters contained in a line of text. Getchar accepts space character.Scanf ("control strings",arg1, arg2, &acirc;&euro;&brvbar;&acirc;&euro;&brvbar;&acirc;&euro;&brvbar;&acirc;&euro;&brvbar; argn);The control string specifies the field format in which the data is to be entered and the arguments arg 1, arg 2, arg n specify the address of locations where the data is stored. Scanf does not accept space character.


How is the getchar function used in a C program?

The getchar() is used in 'C' programming language because it can read the character from the Standard input(i.e..from the user keyboard),and converts in to the ASCII value.


What is function get in C programming?

There is no 'get' in the standard libraries, but for 'getc', 'getch', 'getchar', 'fgetc' etc you can find useful information in the help/manual.


What is the use of getchar?

gets()Reads characters from stdin and stores them as a string into str until a newline character ('\n') or the End-of-File is reached.The ending newline character ('\n') is not included in the string.getchar()Returns the next character from the standard input (stdin).It is equivalent to getc with stdin as its argument. === ===


How do you read a character from the keyboard and will store it in the variable?

Use the scanf() function from the C standard library.


Is that any other way to input data in c language other than scanf function?

read, fread, gets, fgets, getc, fgetc, getchar, getch


Give an example of how getchar function is used in C program.?

The getchar() function is used to read a single character from standard input (stdin) and increment the associated file pointer to point to the next character. The return value is an integer which must be cast to a character. An example demonstrating its usage is shown below. #include &lt;stdio.h&gt; int main() { char buffer[81]; int i, ch; for(i=0; (i&lt;80) &amp;&amp; ((ch = getchar()) != EOF) &amp;&amp; (ch!='\n'); ++i) { buffer[i] = (char) ch; // cast input to a character } buffer[i] = '\0'; // add null-terminator. printf( "You entered: %s\n", buffer); }


Will blank spaces be accepted in getchar?

yes


Explain in details about get char?

#include &lt;stdio.h&gt; The function getchar() returns an int corresponding to the next character in standard input. The value EOF indicates error or end-of-file.


What is the purpose of getch()?

getch() is a way to get a user-inputted character. It can be used to hold program execution, but the "holding" is simply a side-effect of its primary purpose, which is to wait until the user enters a character. getch() and getchar() are used to read a character from screen.


What is the basic purpose and function of an independent laboratory?

basic purpose and function of an independent laboratory