getchar : Reading or Accepting String From User in C
- Reads String Character by Character
Syntax for Accepting String :
- ch = getchar(); // getchar accepts character & stores in ch
Example :
- ch = getchar() ;
- name[0] = getchar();
Live Example : : For Accepting String (Use One of the Loop)
#include<stdio.h> void main() { int i = 0; char name[20]; printf("\nEnter the Name : "); while((name[i] = getchar())!='\n') i++ ; getch(); }
Rules / Facts :
- getchar accepts string Character by character
- Terminating Condition Should be specified
- Here Terminating Condition is : n (i.e Loop will be continue until new line character is entered )

