Giter Site home page Giter Site logo

c_koans's Introduction

c_koans

Build Status

A kōan 公案 (pinyin: gōng'àn) is a story, question, or statement, which is used in Zen practice to provoke the "great doubt" and test a student's progress in Zen practice.

Inspired by ruby koans you may learn the syntax and practices of C through a series of lessons in the form of Unit tests. These preprepared tests are all failing, by going through each one and repairing them to make them pass you will learn a small component of the C programming language.

The test are written in the Criterion unit testing library.

How to run

On Linux/OSX:

  1. Install Criterion
  2. run make clean all
  3. run bin/c_koans
  4. Start fixing!

On Windows:

  1. Get a Linux command line (Cygwin, Windows Linux Subsystem, or whichever you prefer)
  2. Follow the Linux/OSX instructions!

Sections

Inside src/ you will find a file for each of the following topics in C:

  • Basics
  • Pointers
  • Functions
  • Arrays
  • Strings
  • The Preprocessor
  • Control Statements
  • Structs
  • Dataclasses
  • I/O
  • Malloc
  • Linked List Project

The recommended order for fixing the tests is:

  • about_basics.c
  • about_control_statements.c
  • about_functions.c
  • about_pointers.c
  • about_malloc.c
  • about_arrays.c
  • about_strings.c
  • about_structs.c
  • about_dataclasses.c
  • about_printing.c
  • about_io.c
  • about_linked_lists.c
  • about_preprocessor.c

c_koans's People

Contributors

0807jpatel avatar alvarogarcia7 avatar benmardana avatar brian-gavin avatar codecop avatar divjotarora avatar dummyaccount320 avatar jackzheng2496 avatar nbbeeken avatar utagai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

c_koans's Issues

No actual reallocation and UB in about_arrays.c

In the file about_arrays.c on line 81 the array int is allocated with 5 elements (defined on line 80), then in line 96 this array is reallocated again with 5 elements (with the same size variable), and then access to the 6th (on index 5) element of the array (of 5 elements) is undefined behavior

Invalid assert in about_printing.c:27

There is a possible issue in the assert flag where it is expecting "A" from stdout, but a garbage result is actually returned from the stream.
Thanks for making this tho :)

Error in file about_io.c (error: cast to 'FILE *')

When compiling with :

gcc -v
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 9.1.0 (clang-902.0.39.2)
Target: x86_64-apple-darwin17.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

or

(brew --prefix llvm)/bin/clang --version                                                                                           ✓  10066  08:40:09
clang version 8.0.0 (https://llvm.org/git/clang.git 5e499dd14cc6493f0bd62bc6b95580837fb4303f) (https://llvm.org/git/llvm.git 740597761a32c90575ff6c2b2a6245fb2700f565)
Target: x86_64-apple-darwin17.7.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm/bin

On MAC os X high sierra, I allways get executing make clean all:

rm -f -r build bin
/usr/local/opt/llvm/bin/clang -std=gnu11 -Wall -Werror -Wno-unused-function -I include src/about_io.c -c -o build/about_io.o
src/about_io.c:81:26: error: cast to 'FILE *' (aka 'struct __sFILE *') from smaller integer type 'int' [-Werror,-Wint-to-pointer-cast]
    fputs("Hello World", TODO_FP);
                         ^
include/c_koans.h:10:17: note: expanded from macro 'TODO_FP'
#define TODO_FP (FILE*)!NULL
                ^
src/about_io.c:82:26: error: cast to 'FILE *' (aka 'struct __sFILE *') from smaller integer type 'int' [-Werror,-Wint-to-pointer-cast]
    fputs("Hello World", TODO_FP);
                         ^
include/c_koans.h:10:17: note: expanded from macro 'TODO_FP'
#define TODO_FP (FILE*)!NULL
                ^
src/about_io.c:146:19: error: cast to 'FILE *' (aka 'struct __sFILE *') from smaller integer type 'int' [-Werror,-Wint-to-pointer-cast]
    fputs(TODO_S, TODO_FP);
                  ^
include/c_koans.h:10:17: note: expanded from macro 'TODO_FP'
#define TODO_FP (FILE*)!NULL
                ^
3 errors generated.
make: *** [build/about_io.o] Error 1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.