Question 1

Question: Create a C program that reads and writes user's input

Answer:

/*include I/O function for compiler to check*/
#include <stdio.h>

int main(void){
    int c;
    for ( ; ; ){           /*infinite loop*/
    c = getchar();     /*read  a next single character from stdin*/
    if(c == EOF)     /*EOF (end-of-file) is global constant, which is defined in stdio.h  */
        break;           /*if end-of-file, break out of the loop*/
    putchar(c);        /*else, write a single character to stdout*/
    }
    return 0;
}

Output:





There are many other ways to do it



No Response to "Question 1"

Post a Comment

 

Copyright © 2013-2014 Lai Duy Thanh All rights reserved.