Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

atoi() modified to work with positive and negative numbers #140

Open
wants to merge 1 commit into
base: riscv
Choose a base branch
from

Conversation

HeberDamianAlturria
Copy link

To whom it may concern,
my name is Heber Damián Alturria and i have noticed that atoi() only return 0 when we pass as input a string that represent a negative number such as "-1" or if it have a positive sign such as "+1".
To solve the aforementioned situation, i have modified the implementation of atoi() to permit the use of positive and negative signs, resulting in results as interesting as:

  • atoi("204") is going to return the number 204.
  • atoi("-21") is going to return the number -21.
  • atoi("0") is going to return the number 0.
  • atoi("+123") is going to return the number 123.
  • atoi("+00000001") is going to return the number 1.
  • atoi("-000000012") is going to return the number -12.

As you can appreciate, the operation of the atoi() that I have modified is similar to the atoi() provided by the C library called stdlib.h.

thank you very much for reading and I hope you will consider adding the modification I have provided to the atoi().

best regards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant