my_getnbr.c


SUBMITTED BY: Guest

DATE: Nov. 29, 2013, 6:39 p.m.

FORMAT: Text only

SIZE: 523 Bytes

HITS: 1392

  1. int my_getnbr(char *str)
  2. {
  3. int nb;
  4. int neg;
  5. nb = 0;
  6. neg = 1;
  7. while (*str == '+' || *str == '-')
  8. {
  9. if (*str == '-')
  10. neg = neg * -1;
  11. str = str + 1;
  12. }
  13. while (*str != '\0')
  14. {
  15. if (*str >= '0' && *str <= '9')
  16. {
  17. nb = nb * 10;
  18. nb = nb + *str - '0';
  19. str = str + 1;
  20. }
  21. else
  22. return (nb * neg);
  23. }
  24. return (nb * neg);
  25. }

comments powered by Disqus