csev / cc4e Goto Github PK
View Code? Open in Web Editor NEWC Programming for Everybody
Home Page: https://www.cc4e.com/
License: Other
C Programming for Everybody
Home Page: https://www.cc4e.com/
License: Other
Using cc4e.com compiler it did work properly. Using clang or gcc13 did not worked. Maybe I did not knew how to switch to K&R code, I don't know?
The code that did not properly work for me (it gives buss error, core dumped when the input exceeds array size):
#include <stdio.h>
int main() {
char name[11];
printf("Enter your name:\n");
scanf("%[^\n]10s", name);
printf("Hello, %s\n", name);
}
The code that worked for me:
#include <stdio.h>
int main() {
char name[11];
printf("Enter your name:\n");
scanf("%10[^\n]",name);
printf("Hello, %s\n", name);
}
I use a smaller array to demonstrate the code, it's easier to test.
"To compile K&R C code with GCC, you can generally use the default settings of the compiler, as it is designed to support backward compatibility with K&R C code."
While working through the CC4E online C programming course, I encountered a challenge with the exercise RS-8 , specifically related to understanding the pre-validation error messages.
The message "NOT GRADED: You need to read the input." was displayed.
I was using gets() to read the input as I had adapted my code from exercise RS-7.
This led to some confusion because RS-7 was quite similar and explicitly requires the use of gets() and the lecture notes and problem statement did not specify the use of scanf() for RS-8.
I found the validation code on:
# cc4e/tools/ccauto/rs-08-guess.php
# line: 81
function ccauto_require($LAUNCH) {
return array(
array('scanf', 'You need to read the input.'),
array('while', 'You need to read the input until the user gets the correct guess.'),
array('else if', 'This application is best solved using a multi-way if statement (i.e. else if).'),
);
}
I propose updating the pre-validation message to be more explicit in this case.
For example, changing the message to "You need to read the input. (Use scanf)".
I am willing to contribute to this improvement by creating a pull request with the suggested change to the pre-validation message.
Thank you for considering this suggestion. I look forward to any feedback or thoughts on this proposal.
4.8 Block Structure
being followed by
4.10 Recursion
if you compare *s++ == *t++ you will never asign t to s. The == should be =
strcpy(s, t) /* copy t to s; pointer version 3 - corrected*/
char *s, *t;
{
while (*s++ = *t++)
;
}
Would it be possible for you to add to the repo the original scanned images of the book pages, without any image processing?
It appears that the scanned pages are heavily processed, most likely to prepare them for OCR. i.e. all anti-aliasing has been removed and only hard-edged black characters on white background remain.
So, when reading the original book pages, which can be quite enjoyable, is it made less enjoyable by that harsh text.
Thanks for you time.
As you are in the process of creating and testing the "tools", perhaps the following will help you
chapter 1 quiz:
In question 22 "Whay does the ..." -> What...
chapter 2 quiz:
question 1: "int must ... iin length" -> ... in ...
question 8: "None of the above" answer doesn't always appear last, maybe it should be "None of the rest"
question 10: none of the given answers are correct for j, should 42 be 2?
Hope that helps you,
Great work!!
Taking in account C code and the Output, you have a typo on Python side:
print('x',3.5,'i',10)
must be:
print('x',3.5,'i',100)
Declaring a C function as you present is not supported anymore.
int mymult( a, b)
int a, b;
{
...
}
βmustβ be:
int mymult( int a, int b) {
...
}
From my Mac cc I got the following "warning: a function definition without a prototype is deprecated in all versions of C and is not supported in C2x"
Is it a blank page? Or is it missing? File page_178.jpg
Thanks and keep up the good work!
For cc4e.com, in the discussions.
Lesson 11/13 - Tree Maps and Hash Maps
Tools:
Quiz: Tree Maps and Hash Maps
https://www.cc4e.com/lessons_launch/cc_05_quiz
Click on link,
Welcome Stephen Catto from C Programming for Everybody (Instructor)
This quiz has not yet been configured
The same quiz doesn't appear in the course 4 week 6 Coursera version.
https://www.coursera.org/learn/building-objects-in-c/home/week/6
Reported in Coursera version.
https://www.coursera.org/learn/exploring-c/discussions/forums/2XEEzmReEe6hqQqbSjqy1w/threads/KW5gBKOjEe67HQrbxnFcjw
Assignment
cc4e/tools/ccauto/1-04-celsius.php
Expected output in grader example,
This is very similar to ex-1-03 but without the heading ending '\n', which is aligned.
K&R 2: Types, Operators, and Expressions should link to the K&R video about Chapter 2, but currently links to Chapter 1.
Student report, cc4e/lectures/KR-1.pptx. My edit in (...).
With deep respect for Dr. Chuck.
In reviewing the presentation, I found the following errors:
%s\\n
) is inserted in line 7 which breaks the '\n' operatorint i, len=0;
to int i;
for(i=0;self[i];i++) len=i;
to for(i=0;self[i];i++);
for(i=0; self[i]; i++);
The Profile picture of young Dr.Chuck is having cc4e.com as the link instead of access to the full sized picture
Multiple posts. Exercise RS-8: Write a C program
https://www.cc4e.com/tools/ccauto/index.php?PHPSESSID=
The Run Code button isn't working, Reset Code does. To the right-hand side of Reset Code is a little spinner, going for 8 minutes now.
All exercises at - https://www.cc4e.com/lessons/python , picking at random - Object Oriented Programming section 9/13 Implement a Python str class
A posted solution - "For all of the exercises, the "Run Code" button is greyed out and I have to edit the HTML in the Inspect Element section of my browser to remove the "disabled" tag on the button in order to submit my exercises."
Another 2 threads, one post is, 12 days ago
this should do: document.getElementById("runcode").removeAttribute("disabled")
The FOR-statement is not a complete block.
Appendix A seems to be missing.
I read the book with great pleasure :-)
Hi,
I've tried example cc_02_06.c from the long video (at position 1:34:11 in the video). This is the example:
#include <stdio.h>
int main() {
char line[1000];
FILE *hand;
hand = fopen("romeo.txt", "r");
while ( fgets(line, 1000, hand) != NULL ) {
printf("%s", line);
}
}
When I first compiled and run the program it returned "Segmentation fault (core dumped)". I am not a programmer but rather a sysadmin but I knew to compile the code with debug info and then to run gdb ./a.out and then inside gdb to run the program which said:
(gdb) r
Starting program: /home/ovi/learn/c/lessons/a.out
Program received signal SIGSEGV, Segmentation fault.
Address not mapped to object.
0x00000008003595e3 in fgets () from /lib/libc.so.7
Then I've realized I forgot to create the text file from where the program should read. I knew to use gdb but other beginners might not knew that, type the code and their program will crash (at least on linux or freebsd, where I tested the program).
So, I propose a little bit of an improvement to the program:
#include <stdio.h>
int main() {
char line[1000];
FILE *hand;
hand = fopen("romeo2.txt", "r");
if (hand == NULL) {
perror("Error opening file");
return 1;
}
while (fgets(line, sizeof(line), hand) != NULL) {
printf("%s", line);
}
fclose(hand);
return 0;
}
The improvements are:
https://www.cc4e.com/mod/gift/?quiz=chap05.txt
Warning
The asterisk(*) is the correct answer, but is interpreted as incorrect.
Couldn't find the page/code for this.
https://www.cc4e.com/lessons/core
Quiz: Types, Operators, and Expressions
(a) Q7
If the result of the logical expression (12>10) is assignmed to an integer variable in C, what is the value that is assigned?
Typo - is assignmed
Correct answer is expected to be 1 as, 12 > greater than 10, true (would be 0 if false.
Accepted as correct is 0, False.
K&R pg 189 appendix A 7.6 relational operators.
1 discussion report the question option is "\1". A browser render/typo in source issue?
(b) Q12
Since ANSI C does not have a predevined value for 'true', which of these is the most "correct" way to define a true value in ANSI C code?
typo - predevined
typo - #define TRUE (1)
Correct answer would be a non 0 value, that is 1 according to lessons.
Marked as wrong, the TRUE (1). The correct answer is TRUE (0==0) makes sense to me. I've seen this before. Using gcc -ansi to test. Both of those return 1 i.e. non 0 so either would be right.
Section 3.9 of the book is called Goto's and Labels, which seems to be grammatically incorrect. However, since the title of corresponding section in the original book is Goto and Labels, it should be corrected either way.
The course has been configured on Coursera but in the TreeMaps
and HashMaps
section on www.cc4e.com - the quiz says that it is yet to be configured.
I was hoping maybe this is a mistake that needs to be rectified.
https://www.cc4e.com/mod/gift/index.php?PHPSESSID=
The 2nd part is the end of,
The login session expiry duration for www.cc4e.com is very short. While working on my assignment, I encountered an issue where I lost all my code because of the session expiry. I believe there should be a mechanism in place to automatically save the code every few seconds to prevent such incidents. Thank you.
https://www.cc4e.com/lessons_launch/cc4e_00_quiz
"A couple of typos in the chapter 0 quiz: - Q16, Linux is incorrectly spelled as Lunix. - Q19, Linux is incorrectly spelled as Liunx."
Maybe one is a trick answer?
According to the test I did on my Mac, there is an issue related with the C code you present.
scanf is not stoping you to input more than 100 chars on name, and if you want to get 100 chars you need to define the name var with 101 length.
Hey Dr. Chuck,
I'm from your SI311. In my computer, I turn on the darkmode on everything due to my eyes' condition. However, it doesn't quite work when I'm reading the C Language textbook from my browser. I have tried using the "Read Mode" and different plug-ins, but it doesn't load the comment section of the book. I think this is because the source code indicates that you importing content from another md file.
I have to manually change the html styles in my console, which works pretty well:
document.querySelector("body").style.color = "#ffffff"
document.querySelector("body").style.backgroundColor = "#192734"
Do you have any recommendation on enabling darkmode? Or this could be a potential feature to implement?
<h2>1.1 Getting Started</h2>
, we will have to do <h2 id="getting-started">1.1 Getting Started</h2>
or <h2 id="1.1">1.1 Getting Started</h2>
, if we can change the html so that all h2's have an id, we can link the sub headings in Table of Contents to URLs like this https://cc4e.com/book/chap01.md#1.1 or https://cc4e.com/book/chap01.md#getting-startedI stumbled upon the typo with the first then in this sentence
Line 1 in 39b7cde
Not being a native English speaker I was not sure if it should be:
By now, you know when the authors mention the PDP-11
or
By now, you know that when the authors mention the PDP-11
And asked ChatGPT, which came up with some additional suggestions that make sense, IMHO:
Yes, there are a few issues with the sentence you provided. Here's a revised version:
"By now, you know that when the authors mention the PDP-11, they are discussing the challenge of making C work on previous generation computers with short memory words and small amounts of memory, while simultaneously ensuring its compatibility with the incoming generation of computers with larger words and more memory."
This revision clarifies the relationship between the mention of the PDP-11 and the challenge of making C work on different generations of computers. It also improves the overall clarity and structure of the sentence.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.