1
This commit is contained in:
parent
fdd27ce350
commit
2d2bc18a75
BIN
du2/program
Executable file
BIN
du2/program
Executable file
Binary file not shown.
30
du2/program.c
Normal file
30
du2/program.c
Normal file
@ -0,0 +1,30 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#define LINE_SIZE 100
|
||||
|
||||
int main() {
|
||||
char riadok[LINE_SIZE];
|
||||
memset(riadok, 0, LINE_SIZE);
|
||||
|
||||
printf("Zadajte číslo: ");
|
||||
char* r = fgets(riadok, LINE_SIZE, stdin);
|
||||
assert(r != NULL);
|
||||
|
||||
size_t len = strlen(riadok);
|
||||
if (len > 0 && riadok[len - 1] == '\n') {
|
||||
riadok[len - 1] = '\0';
|
||||
}
|
||||
|
||||
char* endptr = NULL;
|
||||
long cislo = strtol(riadok, &endptr, 10);
|
||||
if (*endptr != '\0') {
|
||||
printf("Neplatný vstup! Prosím, zadajte iba celé číslo.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Načítané číslo: %ld\n", cislo);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user