Copy stdin to stdout: Difference between revisions

Content added Content deleted
(→‎C: Made the code portable. The function "getchar" returns an int; storing its result in a char variable can mean the loop comparison is never true if a char is unsigned on your platform. Also, I modified the formatting slightly.)
Tags: Mobile edit Mobile web edit
Line 111: Line 111:
#include <stdio.h>
#include <stdio.h>


int main(){
int main() {
char c;
int c;
while ( (c=getchar()) != EOF ){
while ((c = getchar()) != EOF) {
putchar(c);
putchar(c);
}
}