Compare commits

...

2 Commits

Author SHA1 Message Date
d939f341f9 Merge branch 'main' of git.kemt.fei.tuke.sk:bm271gs/pvjc25 2025-03-06 10:30:34 +00:00
2d2bc18a75 1 2025-03-06 10:21:11 +00:00
2 changed files with 30 additions and 0 deletions

BIN
du2/program Executable file

Binary file not shown.

30
du2/program.c Normal file
View 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;
}