diff --git a/02/alphabet.c b/02/alphabet.c index b83ad59..b7e9060 100644 --- a/02/alphabet.c +++ b/02/alphabet.c @@ -23,7 +23,7 @@ #include #include -#include "myio.h" +#include "../io/myio.h" int main() diff --git a/02/myio.c b/02/myio.c deleted file mode 100644 index 3b0c300..0000000 --- a/02/myio.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include "myio.h" - -unsigned char getSingleChar() -{ - unsigned char result = 'a'; - - result = getchar(); - while(result != '\n' && getchar() != '\n') {} - - return result; -} \ No newline at end of file diff --git a/io/myio.c b/io/myio.c new file mode 100644 index 0000000..be62239 --- /dev/null +++ b/io/myio.c @@ -0,0 +1,27 @@ +#include +#include "myio.h" + +unsigned char getSingleChar() +{ + unsigned char result = 'a'; + + result = getchar(); + while(result != '\n' && getchar() != '\n') {} + + return result; +} + +int getNumber(const char *text) +{ + int number = 0; + int wasSuccessful = 0; + + do + { + printf("%s", text); + wasSuccessful = scanf("%d", &number); + while(getchar() != '\n') {} + } while(!wasSuccessful); + + return number; +} \ No newline at end of file diff --git a/02/myio.h b/io/myio.h similarity index 67% rename from 02/myio.h rename to io/myio.h index c3c8136..ddc86ae 100644 --- a/02/myio.h +++ b/io/myio.h @@ -2,5 +2,6 @@ #define MYIO_H unsigned char getSingleChar(); +int getNumber(const char *text); #endif \ No newline at end of file diff --git a/io/testInput.c b/io/testInput.c new file mode 100644 index 0000000..585bfec --- /dev/null +++ b/io/testInput.c @@ -0,0 +1,11 @@ +#include +#include "../io/myio.h" + +int main() +{ + int number = getNumber("Geben Sie eine Zahl ein: "); + + printf("number: %d\n", number); + + return 0; +} \ No newline at end of file