From 77716bd8df2b4b68f8ca42e4ff33177aff307b1f Mon Sep 17 00:00:00 2001 From: "exercism-solutions-syncer[bot]" <211797793+exercism-solutions-syncer[bot]@users.noreply.github.com> Date: Tue, 31 Mar 2026 13:14:40 +0000 Subject: [PATCH] [Sync Iteration] c/binary/1 --- solutions/c/binary/1/binary.c | 17 +++++++++++++++++ solutions/c/binary/1/binary.h | 8 ++++++++ 2 files changed, 25 insertions(+) create mode 100644 solutions/c/binary/1/binary.c create mode 100644 solutions/c/binary/1/binary.h diff --git a/solutions/c/binary/1/binary.c b/solutions/c/binary/1/binary.c new file mode 100644 index 0000000..2e91f5d --- /dev/null +++ b/solutions/c/binary/1/binary.c @@ -0,0 +1,17 @@ +#include "binary.h" +#include + +int convert(const char *input) +{ + int i = 0; + int number = 0; + + while (input[i] != '\0') + { + if (input[i] != '0' && input[i] != '1') + return (INVALID); + number = number * 2 + (input[i] - '0'); + i++; + } + return (number); +} \ No newline at end of file diff --git a/solutions/c/binary/1/binary.h b/solutions/c/binary/1/binary.h new file mode 100644 index 0000000..19743d3 --- /dev/null +++ b/solutions/c/binary/1/binary.h @@ -0,0 +1,8 @@ +#ifndef BINARY_H +#define BINARY_H + +#define INVALID -1 + +int convert(const char *input); + +#endif