Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. /*
  2. ** EPITECH PROJECT, 2019
  3. ** my_getnbr.c
  4. ** File description:
  5. ** Get nbr from a string.
  6. */
  7.  
  8. int my_getnbr(char const *str)
  9. {
  10. int res = 0;
  11.  
  12. for (int i = 0; str[i] != '\0'; i++) {
  13. if (str[i] > 47 && str[i] < 58) {
  14. int neg = (str[i - 1] == '-') ? 1 : 0;
  15. for (; str[i] > 47 && str[i] < 58; i++)
  16. res = res * 10 + (str[i] - 48);
  17. if (neg == 1)
  18. res *= -1;
  19. return(res);
  20. }
  21. }
  22. return(0);
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement