Skip to content

Commit

Permalink
add read file support to C, solve 22
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Aug 3, 2024
1 parent ae1f9fe commit 962f334
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Olivia's Project Euler Solutions
+------------+--------------------------+--------+-------------------+
| Language | Version | Solved | Status |
+============+==========================+========+===================+
| C | C99+ in: |clang|, |br| | 20 | |Ci| |br| |
| C | C99+ in: |clang|, |br| | 21 | |Ci| |br| |
| | |gcc|, |pcc|, |tcc| |br| | | |C-Cov| |br| |
| | C11+ in: |msvc| [1]_ | | |CodeQL| |
+------------+--------------------------+--------+-------------------+
Expand Down
1 change: 1 addition & 0 deletions c/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ Problems Solved
- ☒ `14 <./src/p0014.c>`__
- ☒ `15 <./src/p0015.c>`__
- ☒ `16 <./src/p0016.c>`__
- ☒ `22 <./src/p0022.c>`__
- ☒ `34 <./src/p0034.c>`__
- ☒ `76 <./src/p0076.c>`__
- ☒ `836 <./src/p0836.c>`__
2 changes: 2 additions & 0 deletions c/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "src/p0015.c"
#include "src/p0016.c"
#include "src/p0017.c"
#include "src/p0022.c"
#include "src/p0034.c"
#include "src/p0076.c"
#include "src/p0836.c"
Expand Down Expand Up @@ -44,6 +45,7 @@ const Answer answers[] = {
{15, 137846528820, p0015},
{16, 1366, p0016},
{17, 21124, p0017},
{22, 871198282, p0022},
{34, 40730, p0034},
{76, 190569291, (unsigned long long (*)()) p0076},
};
Expand Down
1 change: 1 addition & 0 deletions c/test_euler.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
15: 137846528820,
16: 1366,
17: 21124,
22: 871198282,
34: 40730,
76: 190569291,
836: b"aprilfoolsjoke",
Expand Down
29 changes: 29 additions & 0 deletions docs/c/p0022.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
C Implementation of Problem 22
==============================

View source code :source:`c/src/p0022.c`

Includes
--------

- `utils.h <./utils.html>`__

Solution
--------

.. c:function:: int cmpstr(const void *a, const void *b)
A wrapper around ``strcmp()`` to adapt it for ``qsort()``
.. c:function:: unsigned long long p0022()
.. c:function:: int main(int argc, char const *argv[])
.. note::
This function is only present in the Python test runner, or when compiling as a standalone program.
It is not present when compiling for the Unity test runner.
.. literalinclude:: ../../c/src/p0022.c
:language: C
:linenos:
18 changes: 18 additions & 0 deletions docs/c/utils.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
utils.h
=======

View source code :source:`c/src/include/utils.h`

.. c:namespace-push:: utils
.. c:function:: char *get_data_file(const char *name)
Return a character array containing thr whole contents of a file found in _data.
.. c:function:: char *get_parent_directory(const char *name, const unsigned int levels)
.. c:namespace-pop::
.. literalinclude:: ../../c/src/include/utils.h
:language: C
:linenos:
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ Problems Solved
+-----------+------------+------------+------------+------------+------------+------------+
|:prob:`21` | | | | |:py-d:`0021`| |
+-----------+------------+------------+------------+------------+------------+------------+
|:prob:`22` | | | | |:py-d:`0022`|:rs-d:`0022`|
|:prob:`22` |:c-d:`0022` | | | |:py-d:`0022`|:rs-d:`0022`|
+-----------+------------+------------+------------+------------+------------+------------+
|:prob:`23` | | | | |:py-d:`0023`| |
+-----------+------------+------------+------------+------------+------------+------------+
Expand Down

0 comments on commit 962f334

Please sign in to comment.