lOMoAR cPSD| 62301842
CS136 LECTURE NOTES: INTRODUCTION TO POINTERS AND FUNCTIONS
IN C | VERIFIED STUDY | 2026 STUDY UPDATES | 100% CORRECT
UW: CS136
readchar
Write a program that implements a readchar function like the read_char function that we have been using in the course.
main.c ws_read.expect ws_read.in ws_ignore.expect ws_ignore.in
- Add File
1 #include "cs136.h"
2
3 // Your documentation goes here. 4 char
readchar(bool whitespace_behaviour) { 5 //
Your implementation goes here.
6 return ' ';
7 }
8
9 int main(void) { 10 // Registering READ_WHITESPACE and IGNORE_WHITESPACE
11 const int WS_READ = lookup_symbol("READ_WHITESPACE"); 12 const int WS_SKIP =
lookup_symbol("IGNORE_WHITESPACE");
13
14 // Reading whitespace behaviour from input 15 int ws_mode = read_symbol();
16
17 while (true) { 18 char ch = READ_CHAR_FAIL; 19 if (ws_mode == WS_READ) { 20 ch
= readchar(READ_WHITESPACE); 21 } else if (ws_mode == WS_SKIP) { 22 ch =
readchar(IGNORE_WHITESPACE); 23 } else { 24 printf("ERROR: Invalid whitespace
behaviour.\n"); 25 break;
26 }
27
Code Output
, lOMoAR cPSD| 62301842
factorial
Write a program that reads a number from input and outputs the factorial. A factorial is calculated by
multiplying all whole numbers from the number down to 1.
main.c - Add File
1 #include "cs136.h"
2
3 // Your documentation goes here. 4
void factorial(int n, int *result) { 5
// Your implementation goes here.
6 }
7
8 int main() { 9 int fact = 0; 10 int num = 0;
11 // Your implementation goes here.
12 // * Read fact and num1 from input .
13 // * Call factorial.
14 printf("The factorial of %d is %d.\n", num, fact);
15 }
Code Output
CS136 LECTURE NOTES: INTRODUCTION TO POINTERS AND FUNCTIONS
IN C | VERIFIED STUDY | 2026 STUDY UPDATES | 100% CORRECT
UW: CS136
readchar
Write a program that implements a readchar function like the read_char function that we have been using in the course.
main.c ws_read.expect ws_read.in ws_ignore.expect ws_ignore.in
- Add File
1 #include "cs136.h"
2
3 // Your documentation goes here. 4 char
readchar(bool whitespace_behaviour) { 5 //
Your implementation goes here.
6 return ' ';
7 }
8
9 int main(void) { 10 // Registering READ_WHITESPACE and IGNORE_WHITESPACE
11 const int WS_READ = lookup_symbol("READ_WHITESPACE"); 12 const int WS_SKIP =
lookup_symbol("IGNORE_WHITESPACE");
13
14 // Reading whitespace behaviour from input 15 int ws_mode = read_symbol();
16
17 while (true) { 18 char ch = READ_CHAR_FAIL; 19 if (ws_mode == WS_READ) { 20 ch
= readchar(READ_WHITESPACE); 21 } else if (ws_mode == WS_SKIP) { 22 ch =
readchar(IGNORE_WHITESPACE); 23 } else { 24 printf("ERROR: Invalid whitespace
behaviour.\n"); 25 break;
26 }
27
Code Output
, lOMoAR cPSD| 62301842
factorial
Write a program that reads a number from input and outputs the factorial. A factorial is calculated by
multiplying all whole numbers from the number down to 1.
main.c - Add File
1 #include "cs136.h"
2
3 // Your documentation goes here. 4
void factorial(int n, int *result) { 5
// Your implementation goes here.
6 }
7
8 int main() { 9 int fact = 0; 10 int num = 0;
11 // Your implementation goes here.
12 // * Read fact and num1 from input .
13 // * Call factorial.
14 printf("The factorial of %d is %d.\n", num, fact);
15 }
Code Output