answersLogoWhite

0


Best Answer

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 <stdio.h>

int main()

{

char buffer[81];

int i, ch;

for(i=0; (i<80) && ((ch = getchar()) != EOF) && (ch!='\n'); ++i)

{

buffer[i] = (char) ch; // cast input to a character

}

buffer[i] = '\0'; // add null-terminator.

printf( "You entered: %s\n", buffer);

}

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Give an example of how getchar function is used in C program.?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Write a program to calculate the area of a cylinder using a function?

give an example of calculation of mathematics


How do you write a program using c plus plus to calculate change of dollar?

Here is a program that would calculate the change of a dollar: #include &lt;stdio.h&gt; int main(); { float total=0; float bill=0; float pay=0; printf("How much do you have to pay: "); scanf("%f", &amp;bill); printf("How much did you give out: "); scanf("%f", &amp;pay); total = bill - pay; printf("Your change is: %.2f", total); /*.2 meant 2 digits after the decimal*/ getchar(); getchar(); /*I use getchar(); to pause the program till you press 'enter'*/ return 0; } Here is the program running: How much many do you have to pay: 5.64 /*5.64 is user input*/ How much many did you give out: 4.72 /*You can redo the questions if need be*/ Your change is: 0.92 /*This is where you press 'enter' to close the program from the getchar();*/ I hope this helped :D


Give a business example of how loops can be beneficial in a program?

Give a business example of how loops can be beneficial in a program?


Give an example of an email program?

palawan


How do you you rewrite a rule as a function?

You need to give an example of the rule and the function you want.


Can you give example of an equadratic function?

No, because there is no such thing.


Can you give more than one main function in the program?

In any source-files, the function names must be unique. In any program (which might be created from multiple source-files), the public function names must be unique.


What is the meaning of statement missing in function main in c language?

Every C program must have a function, named main(), which is where the program starts execution. If there is no function main(), the computer does not know where to start running the program. The function main() must also do something; if it is just empty, some smarter compilers will note that there is nothing for the program to do, and will give this sort of error message to indicate that you forgot to tell the program what to do.


Give na example whic isnot exponential function?

f(x) = 2x it is linear function


Can somebody give me the program to find simple interest using friend function in c plus plus?

Here is an example program: class obj{ public: float p,n,r,si; friend void calc( obj temp); }; void calc( obj temp){ si = (p*n*r)/100; } The initialization and function calling is essential.


Give an example of computer program?

A C program #include &lt;stdio.h&gt; int main() { printf("Hello, world!"); }


How do you pass in Anna university chennai?

Define c-program and give an example