Right Click to Search

Thursday, January 14, 2025

Getchar : Reading or Accepting String Character by Character


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 :
  1. ch = getchar() ;
  2. name[0] = getchar();

Live Example : : For Accepting String (Use One of the Loop)
#include
void main()
{ 
int i = 0; 
char name[20]; 
printf("\nEnter the Name : "); 
while((name[i] = getchar())!='\n'))
        i++ ;
getch();
} 

Rules / Facts : 
  1. getchar accepts string Character by character
  2. Terminating Condition Should be specified
  3. Here Terminating Condition is : \n (i.e Loop will be continue until new line character is entered )

Bookmark & Share

Tags / Keywords : | , ,

Stumble
Delicious
Technorati
Twitter
Facebook

0 Comments:

Post a Comment

Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email

 

Learn C Programming Copyright © 2010 LKart Theme is Designed by Lasantha, Free Blogger Templates