Funkcija atoi v C-ju
Iz E-študij, proste zakladnice študentskega znanja
#include <stdio.h> main(int argc, char *argv[]) { int i; if(argc==2) { sscanf(argv[1], "%d", &i); printf("%d\n", i); } else { printf("Hint: type %s num, where num is a ",argv[0]); printf("number you want to convert."); } }
- my atoi.
#include <stdio.h> int myAtoi(char s[]) { int i,n; i= n = 0; while(s[i]>='0'&&s[i]<='9') { n=n*10 + s[i]-'0'; i++; } return (n); } int main () { int n; char s[]="122.14"; n=myAtoi(s); printf("%d\n",n); return (0); }