csev / cc4e

C Programming for Everybody
https://www.cc4e.com/
Other
260 stars 90 forks source link

I tried to compile the code from minute 1:29:36 from youtube video of the course #97

Closed avlcat closed 4 weeks ago

avlcat commented 4 weeks ago

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

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

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."

csev commented 4 weeks ago

Found it. I changed the sample code and the PowerPoint. I will update the video - but it is hard to get all the copies of all the videos updated. I can update my www.dj4e.com copy most easily.

csev commented 4 weeks ago

I uploaded the new video to youtube. Thanks.

avlcat commented 4 weeks ago

wow that was fast, thank you ! (sorry I am a beginner, I did not knew if it's an issue with the code or I am doing something wrong)