Atoi (jazyk C): Rozdiel medzi revíziami
Skočit na navigaci
Skočit na vyhledávání
Riadok 35: | Riadok 35: | ||
printf("Hodnota stringu = %s, Hodnota integeru = %d\n", str, val); | printf("Hodnota stringu = %s, Hodnota integeru = %d\n", str, val); | ||
− | return(0); | + | strcpy(str, "MTF STU"); |
+ | val = atoi(str); | ||
+ | printf("Hodnota stringu = %s, Hodnota integeru = %d\n", str, val); | ||
+ | |||
+ | return(0); | ||
} | } | ||
</source> | </source> | ||
Riadok 42: | Riadok 46: | ||
<source lang="c"> | <source lang="c"> | ||
Hodnota stringu = 98993489, Hodnota integeru = 98993489 | Hodnota stringu = 98993489, Hodnota integeru = 98993489 | ||
+ | Hodnota stringu = MTF STU, Hodnota long int = 0 | ||
</source> | </source> | ||
<ref>https://www.tutorialspoint.com/c_standard_library/c_function_atoi.htm</ref> | <ref>https://www.tutorialspoint.com/c_standard_library/c_function_atoi.htm</ref> | ||
==Odkazy== | ==Odkazy== |
Verzia zo dňa a času 15:09, 9. máj 2020
<ctype.h> | <limits.h> | <stdio.h> | <stdlib.h> | <math.h> | <string.h> | <time.h> |
---|---|---|---|---|---|---|
isalnum |
printf |
system |
Funkcia atoi
knižnica | stdlib.h |
popis | analýza stringu |
Úplný funkčný prototyp
int atoi(const char *str)
Podrobný popis funkcie
Analyzuje string a jeho obsah interpretuje ako celé číslo typu integer
Parametre
- str - vyjadrenie čísla v parametri string reprezentujúce integer
Návratová hodnota
Táto funkcia vráti prevedené číslo typu string na 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 int val;
7 char str[20];
8
9 strcpy(str, "98993489");
10 val = atoi(str);
11 printf("Hodnota stringu = %s, Hodnota integeru = %d\n", str, val);
12
13 strcpy(str, "MTF STU");
14 val = atoi(str);
15 printf("Hodnota stringu = %s, Hodnota integeru = %d\n", str, val);
16
17 return(0);
18 }
Výstup
Hodnota stringu = 98993489, Hodnota integeru = 98993489
Hodnota stringu = MTF STU, Hodnota long int = 0