Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C text file

Name: Anonymous 2010-12-14 20:17

Can you guys PLEASE show me a very, very basic C program that writes input to a text file?

Name: Anonymous 2010-12-15 0:37

#include <stdio.h>
#include <stdlib.h>
int main(void) {
  int c;
  while ((c = getchar()) != EOF) putchar(c);
  return ferror(stdin) || ferror(stdout) ? EXIT_FAILURE : 0;
}


This writes input received on stdin to stdout. Redirecting stdout to a file is a job best left to the shell (if you don't know what this means, Google shell redirection).

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List