summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLevi Bostian <levi.bostian@gmail.com>2013-08-31 13:06:37 -0500
committerLevi Bostian <levi.bostian@gmail.com>2013-08-31 13:06:37 -0500
commitf1b1fd8e2efd6c30e553aae1c4f6cc28a6554e8f (patch)
treed7f3f1bc58350129248080581b4406656b24db36
parentdba7ec8b9643f693bdb023f9827999b2b14d008b (diff)
Add clarity to EOF. Add %ld for longs in C
-rw-r--r--c.html.markdown11
1 files changed, 7 insertions, 4 deletions
diff --git a/c.html.markdown b/c.html.markdown
index 7010b9d5..869ab984 100644
--- a/c.html.markdown
+++ b/c.html.markdown
@@ -34,6 +34,7 @@ Multi-line comments look like this. They work in C89 as well.
"%3d" // minimum length of 3 digits for integer (right justifies text)
"%s" // string
"%f" // float
+"%ld" // long
"%3.2f" // minimum 3 digits left and 2 digits right decimal float
"%7.4s" // (can do with strings too)
"%c" // char
@@ -429,10 +430,12 @@ void str_reverse(char *str_in)
// Built in functions:
// from stdio.h:
-int c = getchar(); //reads character from user. If user types hello, only h is read.
-// getchar() can be stored into int or char. I am using int because char is not large
-// enough to store EOF used below.
-while (c != EOF) { // EOF is value for "end of file". Linux: CTRL+D, Windows: CTRL+X
+int c = getchar(); //reads character from input. If input = hi, only h is read.
+// getchar() can be stored into int or char. I am using int because
+// char is not large enough to store EOF used below.
+while ((c = getchar()) != EOF) { // EOF constant "end of file".
+ // Linux: CTRL+D, Windows: CTRL+X
+ // must have () around getchar() as != is run before =.
putchar(c); //prints character (without newline at end)
char c = getchar();
}