How to use putc to output characters to stdout in C

1 Answer

0 votes
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    int result = 0;
    for (char ch = 'a'; (result != EOF) && (ch != 'z'); ch++)
        result = putc(ch, stdout);

    if (result == EOF) {
        if (ferror(stdout)) {
            puts("putc() error");
            exit(EXIT_FAILURE);
        }
    }

    return 0;
}




/*
run:

abcdefghijklmnopqrstuvwxy

*/

 



answered Feb 4, 2023 by avibootz

Related questions

1 answer 139 views
2 answers 205 views
205 views asked Jan 25, 2016 by avibootz
1 answer 215 views
1 answer 241 views
...