mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-25 00:06:47 +03:00
Add clarity to EOF. Add %ld for longs in C
This commit is contained in:
parent
dba7ec8b96
commit
f1b1fd8e2e
@ -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)
|
"%3d" // minimum length of 3 digits for integer (right justifies text)
|
||||||
"%s" // string
|
"%s" // string
|
||||||
"%f" // float
|
"%f" // float
|
||||||
|
"%ld" // long
|
||||||
"%3.2f" // minimum 3 digits left and 2 digits right decimal float
|
"%3.2f" // minimum 3 digits left and 2 digits right decimal float
|
||||||
"%7.4s" // (can do with strings too)
|
"%7.4s" // (can do with strings too)
|
||||||
"%c" // char
|
"%c" // char
|
||||||
@ -429,10 +430,12 @@ void str_reverse(char *str_in)
|
|||||||
|
|
||||||
// Built in functions:
|
// Built in functions:
|
||||||
// from stdio.h:
|
// from stdio.h:
|
||||||
int c = getchar(); //reads character from user. If user types hello, only h is read.
|
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
|
// getchar() can be stored into int or char. I am using int because
|
||||||
// enough to store EOF used below.
|
// 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
|
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)
|
putchar(c); //prints character (without newline at end)
|
||||||
char c = getchar();
|
char c = getchar();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user