C getchar putchar and break when press escape key

//main.c
#include <stdio.h> void getPutChar(); main() { getPutChar(); } void getPutChar() { char c; while((int)(c=getchar())!=27) { putchar(c); } }

Compile

cc main.c -o h1

Run

./h1

 

 

 

 

//main.c

#include <stdio.h>


main()
{
   getPutChar();
}

void getPutChar()
{
    char c;
    while((c=getchar())!=27)
    {
        putchar(c);
    } 
}

 

Compile

cc main.c -o h1

Run

./h1

 

 

 

main()
{
   printChar();
}

void printChar()
{
    int c;
    c=getchar();
    while(c!=27)
    {
        putchar(c);
        c=getchar();
    }
}

 

main()
{
   printGetPutChar();
}

void printGetPutChar()
{
    int c;
    while((c=getchar())!=27)
    {
        putchar(c);
    }
}

 

 

 

 

main()
{
   getEOFDemo();
}

void getEOFDemo()
{
    int c;
    while((c=getchar())!=EOF)
    {
        putchar(c);
    }
}

 

 

 

The EOF can be input via Ctrl+D key.

posted @ 2022-08-07 16:50  FredGrit  阅读(27)  评论(0编辑  收藏  举报