- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create a customized atoi() function in C language?
The atoi() is predefined function used to convert a numeric string to its integer value.
Create a customized atoi()
The atoi() only converts a numeric string to integer value, so we need to check the validity of the string.
If this function encounters any non-numeric character in the given string, the conversion from string to integer will be stopped.
Example
#include <stdio.h> #include <stdlib.h> #include <string.h> int main(){ int value; char string1[] = "3567"; value = atoi(string1); printf("String value = %s
", string1); printf("Integer value = %d
", value); char string2[] = "TutorialsPoint"; value = atoi(string2); printf("String value = %s
", string2); printf("Integer value = %d
", value); return (0); }
Output
String value = 3567 Integer value = 3567 String value = TutorialsPoint Integer value = 0
Advertisements