Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » BeginnersRSS Feeds

PROGRAM TO READ A LINE OF TEXT FROM TERMINAL

Posted By: Alicia Hughes     Category: C Programming     Views: 6325

WRITE A PROGRAM TO READ A LINE OF TEXT FROM TERMINAL.

Code for PROGRAM TO READ A LINE OF TEXT FROM TERMINAL in C Programming

   #include  <stdio.h>                                         
   main( )                                                     
   {                                                           
       char  line[81], character;                              
       int   c;                                                
       c = 0;                                                  
       printf("Enter text. Press <Return> at end\n");          
       do                                                      
       {                                                       
           character = getchar();                              
           line[c]   = character;                              
           c++;                                                
       }                                                       
       while(character != '\n');                                
       c = c - 1;                                              
       line[c] = '\0';                                         
       printf("\n%s\n", line);                                 
   }                                                           

Output                                                      
                                                               
   Enter text. Press <Return> at end                           
   Programming in C is interesting.                            
   Programming in C is interesting.                            
   Enter text. Press <Return> at end                           
   National Centre for Expert Systems, Hyderabad.              
   National Centre for Expert Systems, Hyderabad.              
  
Share: 


Didn't find what you were looking for? Find more on PROGRAM TO READ A LINE OF TEXT FROM TERMINAL Or get search suggestion and latest updates.

Alicia Hughes
Alicia Hughes author of PROGRAM TO READ A LINE OF TEXT FROM TERMINAL is from London, United Kingdom.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!