Add number input.
This commit is contained in:
parent
63c0399302
commit
474138d53f
@ -23,7 +23,7 @@
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "myio.h"
|
||||
#include "../io/myio.h"
|
||||
|
||||
|
||||
int main()
|
||||
|
||||
12
02/myio.c
12
02/myio.c
@ -1,12 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include "myio.h"
|
||||
|
||||
unsigned char getSingleChar()
|
||||
{
|
||||
unsigned char result = 'a';
|
||||
|
||||
result = getchar();
|
||||
while(result != '\n' && getchar() != '\n') {}
|
||||
|
||||
return result;
|
||||
}
|
||||
27
io/myio.c
Normal file
27
io/myio.c
Normal 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;
|
||||
}
|
||||
@ -2,5 +2,6 @@
|
||||
#define MYIO_H
|
||||
|
||||
unsigned char getSingleChar();
|
||||
int getNumber(const char *text);
|
||||
|
||||
#endif
|
||||
11
io/testInput.c
Normal file
11
io/testInput.c
Normal 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;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user