-
Notifications
You must be signed in to change notification settings - Fork 0
/
char-io_char_copy.c
48 lines (41 loc) · 1.06 KB
/
char-io_char_copy.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
* @file char_copy.c
* @author kunal jain ([email protected])
* @brief Program to copy its input to its output
* one character at a time.
* @version 0.1
* @date 2022-01-31
*
* @copyright Copyright (c) 2022
*
*/
#include<stdio.h>
int main(void) {
// Why int?
// We must declare c to be big enough to hold any
// value that getchar returns.
int c;
// Variable Initialization
c = getchar();
// Variable Initialization;
// While (test_condition) {
// statement;
// Counter statement;
// }
//
// We evaluate the test_condition at the begining and
// then at every iteration of the loop.
//
// Unlike for loop, we are not using any counter variable
// inside loop brackets.
// We will use counter variable in while loop generally
// with other statements that we want to execute in loop.
//
// EOF -> Integer defined in <stdio.h>
while ( c != EOF) {
putchar(c);
// Counter statement
c = getchar();
}
return 0;
}