summaryrefslogtreecommitdiff
path: root/reference/C/PROBLEMS/unix2dos.c
diff options
context:
space:
mode:
Diffstat (limited to 'reference/C/PROBLEMS/unix2dos.c')
-rw-r--r--reference/C/PROBLEMS/unix2dos.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/reference/C/PROBLEMS/unix2dos.c b/reference/C/PROBLEMS/unix2dos.c
new file mode 100644
index 0000000..f5992ea
--- /dev/null
+++ b/reference/C/PROBLEMS/unix2dos.c
@@ -0,0 +1,30 @@
+/*************************************************************************
+ *
+ * problem: Convert Unix files to DOS format.
+ * Method: Program scans for hex '0A' (LF) and replaces it with hex '0D0A' (CRLF)
+ * todo: Prompt the user for a filename, and check it exists.
+ * Author: M J Leslie
+ * Date: 12-Mar-94
+ *
+ *************************************************************************/
+
+#include <stdio.h> /* printf, putchar, fopen, fclose */
+
+#define LF 10
+#define CR 13
+#define FILENAME "unix2dos.c"
+
+main()
+{
+FILE *fptr; /* Pointer to file */
+char ch; /* File buffer */
+
+fptr = fopen(FILENAME, "r");
+
+while ( (ch = fgetc(fptr)) != EOF ) /* read characters until EOF */
+ {
+ if ( ch == LF ) printf("%c", CR); /* add CR if we see an LF */
+ putchar(ch); /* write byte */
+ }
+fclose(fptr);
+}