cmc/learn

Archived

My personal learning area. learning notes personal

Commit 9b2d2f2e13

9b2d2f2e13d07938403d21917d6a342ff184cd84

parent: 190abf91b8

Verified · cmc

cmc <hello@cleberg.net> · 2026-11-01 05:45 UTC

Use strtol in guess.c; open file as UTF-8 in cat.py

Ref #1

Layout: unified · split

c/guess.c +1 −1
@@ -24,7 +24,7 @@ int main() {
24 if(fgets(line, sizeof line, stdin) != NULL) 24 if(fgets(line, sizeof line, stdin) != NULL)
25 { 25 {
26 // Convert user input to an integer 26 // Convert user input to an integer
27 int user_input = atoi(line); 27 int user_input = (int)strtol(line, NULL, 10);
28 28
29 // Do the main comparison to determine if the guess is correct 29 // Do the main comparison to determine if the guess is correct
30 if (user_input == random_number) { 30 if (user_input == random_number) {
python/cat.py +1 −1
@@ -7,7 +7,7 @@ args = parser.parse_args()
7 7
8# Open the file using the `file` argument 8# Open the file using the `file` argument
9path = args.file 9path = args.file
10with open(path, 'r') as file: 10with open(path, 'r', encoding='utf-8') as file:
11 # Read and print the file contents 11 # Read and print the file contents
12 contents = file.read() 12 contents = file.read()
13 print(contents) 13 print(contents)