It's just a nasty trick to prevent the DOS-shell-window from closing when the program terminates.
It's strictly for homeworks/school-projects, do not do it in real programs.
OS-dependent. For DOS use functions kbhit and getch from conio.h
dnf install ncurses-devel
#include <stdio.h> #include<process.h> #include<conio.h> void main() { float n,i,c; printf("Enter the number"); scanf("%d",&n); for(i=1;i<=n/2;i++) { c=n/i; if(c==i) { printf("Perfect Square"); getch(); exit(0); } printf("Not a Perfect Square"); getch(); }
then your program will never ends, too unless you pressing the ctrl+c or kill it through your os. can i know the purpose of you creating the loop that never ends? is it just a mistake or are you doing it on purpose?
There is a 'getch' in 'conio.h' which has nothing to do with 'iostream'.
i want a coding of a program of a calculator using graphics in c language??
#include<stdio.h> void main() { int r=10; float pi=3.14,c; c=pi*r*r; printf("Area of the circle=%f",c); getch(); }
How can I program that when the user press a key, it will automatically process like 4 example:The user press wYou just press the key 'w'Not scanf...I think it's getch but I don't know how. It have errors.
Text files, mainly. The name of the files usually ends with .C and .H (lowercase in unix).
getch is used for console applications and it's very useful because in a way how windows work when a console application has finished it's part windows closes it automatically with the code 0 meaning that program did not have any problems while was running. To prevent automatic shutdown for console applications getch can be used. So, when your program has finished all operations it will wait for an input (basically you will have to press any key to finish the application) from the user.
void main() { int a=2,b=5; b=a+b; a=b-a; b=b-a; getch(); }
Gets one character (or keystroke) without buffering or echoing; beware: getch is not part of the standard library.