BEGINNING WITH C – INPUT-OUTPUT IN C LANGUAGE

BEGINNING WITH C LANGUAGE

EXAMPLE 3 – TAKING STRING VALUE AS INPUT

#include<stdio.h>

#include<conio.h>

void main()

{

clrscr();

char str[20];

scanf(“%s”, str);

…………..

getch();

}

In the above example, the control string contains one conversion specification character i.e. %s.. Generally, this implies that the user should enter a string value as input. Especially relevant, we will not place & sign prior to the variable str. Further, the compiler will store that value in the variable str.

 

2. getchar()

First of all, getchar() is one of the library functions and macros also which we use for Character Input/Output. Basically, getchar() Function reads a single character from the Standard input.

Also, the function getchar() works by reading a single character from the standard input stream stdin.. And, returns it to the program.

Further, the syntax of getchar() function is..

int getchar(void);

Now, Following is the example of getchar() function –

#include<stdio.h>

#include<conio.h>

void main()

{

clrscr();

char ch;

printf(“ENTER ANY CHARACTER – “);

ch=getchar();

…………..

getch();

}

 

3. getch()

Basically, getch() is a non-standard function. Further,this function is present in header file “conio.h“. Also, This is mostly applicable in compilers like Turbo C.

Now, similar to other input functions.. Function getch() also reads a single character from the keyboard. But, there’s no use of any buffer by getch() function.. Therefore, the character which the user inputs immediately returns without waiting for the enter key.

Further, the syntax of getch() function is..

int getch(void);

Now, Following is the example of getch() function –

#include<stdio.h>

#include<conio.h>

void main()

{

clrscr();

char ch;

ch=getch();

…………..

}

Leave a comment

Your email address will not be published. Required fields are marked *