
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
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
- Related Articles
- String to Integer (atoi) in C++
- Create a DataFrame with customized index parameters in Pandas
- How to create a pointer for strings using C language?
- Write your own atoi() in C++
- Recursive Implementation of atoi() in C++
- How to use Pre-defined mathematical function in C language?
- isalnum() function in C Language
- isupper() function in C Language
- How to pass entire array as an argument to a function in C language?
- What is a malloc function in C language?
- How to add two complex numbers by passing structure to a function in C language?
- How to pass entire structure as an argument to function in C language?
- Enum with Customized Value in C#
- Explain feof() function in C language with a program
- Explain Squeeze Function C language

Advertisements