Read from the Device File Keyboard - C File

C examples for File:Standard Device

Description

Read from the Device File Keyboard

Demo Code

#include <stdio.h>

int main()/* w ww.j  a v  a2s  . co m*/
{
     char text[500];
     int m, n = 0, p;
     puts("Type the text. Strike the function");
     puts("key F6 to signify the end of this file.");
    
     m = fgetc(stdin);
    
     while(m != EOF){
          text[n] = m;
          n = n + 1;
          m = fgetc(stdin);
     }
     puts("Contents of device file \"keyboard\":");
    
     for(p = 0; p < n; p++)
         putchar(text[p]);
    
     return(0);
}

Result

Predefined Pointers to FILE Constants for Device Files

Pointer to FILE Constants Device File
stdin Keyboard
stdout Monitor
stderr Monitor

Related Tutorials