31 lines
663 B
C
31 lines
663 B
C
#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;
|
|
}
|