diff --git a/include/string.h b/include/string.h new file mode 100644 index 0000000..eba99dd --- /dev/null +++ b/include/string.h @@ -0,0 +1,3 @@ +#pragma once + +int strcmp(const char* str1, const char* str2); \ No newline at end of file diff --git a/src/kernel.c b/src/kernel.c index de1d5ab..bc9fd97 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -1,5 +1,6 @@ #include "io.h" #include "convert.h" +#include "string.h" void print_clippy(); @@ -24,19 +25,19 @@ void main() { uart_puts("\n\nPlease enter first operand\n"); uart_puts("📎 "); - int a = stoi(uart_gets(buffer)); - - uart_puts("\nPlease enter second operand\n"); - uart_puts("📎 "); uart_gets(buffer); - - if(buffer == "clippy") + + if(!strcmp(buffer, "clippy")) { print_clippy(); continue; } - int b = stoi(buffer); + int a = stoi(buffer); + + uart_puts("\nPlease enter second operand\n"); + uart_puts("📎 "); + int b = stoi(uart_gets(buffer)); uart_puts("\n"); uart_puts(itoa(a, buffer)); diff --git a/src/string.c b/src/string.c new file mode 100644 index 0000000..3b4c903 --- /dev/null +++ b/src/string.c @@ -0,0 +1,12 @@ +#include "string.h" + +int strcmp(const char* str1, const char* str2) +{ + while(*str1) + { + int diff = *str1++ - *str2++; + if(diff) return diff; + } + + return 0; +} \ No newline at end of file