Add number input.

This commit is contained in:
paulusja
2026-04-16 13:43:54 +02:00
parent 63c0399302
commit 474138d53f
5 changed files with 40 additions and 13 deletions
+27
View File
@@ -0,0 +1,27 @@
#include <stdio.h>
#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;
}
+7
View File
@@ -0,0 +1,7 @@
#ifndef MYIO_H
#define MYIO_H
unsigned char getSingleChar();
int getNumber(const char *text);
#endif
+11
View File
@@ -0,0 +1,11 @@
#include <stdio.h>
#include "../io/myio.h"
int main()
{
int number = getNumber("Geben Sie eine Zahl ein: ");
printf("number: %d\n", number);
return 0;
}