Atol (jazyk C): Rozdiel medzi revíziami

Z Kiwiki
Skočit na navigaci Skočit na vyhledávání
(Vytvorená stránka „{{Funkcie jazyka c}} __NOTOC__ ==Funkcia atoi== <properties> knižnica=stdlib.h popis=analýza stringu </properties> Úplný funkčný prototyp <source lang="c" long in…“)
 
Riadok 8: Riadok 8:
  
 
Úplný funkčný prototyp
 
Úplný funkčný prototyp
<source lang="c"
+
<source lang="c">
 
long int atol(const char *str)
 
long int atol(const char *str)
 
</source>
 
</source>
Riadok 23: Riadok 23:
 
==Príklad==
 
==Príklad==
 
<source lang="c" line>
 
<source lang="c" line>
Live Demo
 
 
#include <stdio.h>
 
#include <stdio.h>
 
#include <stdlib.h>
 
#include <stdlib.h>

Verzia zo dňa a času 15:10, 9. máj 2020

Rozdelenie funkcií jazyka C podľa knižníc, v ktorých sú definované
<ctype.h> <limits.h> <stdio.h> <stdlib.h> <math.h> <string.h> <time.h>

isalnum
isalpha
isdigit
isgraph
islower
isprint
ispunct
isspace
isupper
isxdigit

printf
scanf
getc
putc
getchar
putchar
fprintf
fscanf
fgetc
fputc
fopen
fclose
feof

system
malloc
qsort
rand
srand
atoi
atol
atof
itoa
div
abs
labs

pow
fabs
exp
log
log10
sqrt
ceil
sin
cos

strlen
strcmp
strchr
strcpy
strstr
strcat
strncat

clock
time

Funkcia atoi

knižnica

stdlib.h

popis

analýza stringu


Úplný funkčný prototyp

long int atol(const char *str)

Podrobný popis funkcie

Funkcia knižnice C long int atol(const char * str) prevádza argument string na long int.

Parametre

  • str - vyjadrenie čísla v parametri string reprezentujúce integer

Návratová hodnota

Táto funkcia vráti prevedené číslo typu string na long integer. Ak nebolo možné vykonať platný prevod, vráti nulu.

Príklad

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <string.h>
 4 
 5 int main () {
 6    long val;
 7    char str[20];
 8    
 9    strcpy(str, "98993489");
10    val = atol(str);
11    printf("Hodnota stringu = %s, Hodnota long int = %ld\n", str, val);
12 
13    strcpy(str, "MTF STU");
14    val = atol(str);
15    printf("Hodnota stringu = %s, Hodnota long int = %ld\n", str, val);
16 	
17    return(0);
18 }

Výstup: </source lang="c"> Hodnota stringu = 98993489, Hodnota long int = 98993489 Hodnota stringu = MTF STU, Hodnota long int = 0 </source> [1]

Odkazy