
- 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 convert a string to a integer in C
First extract characters from left bracket '(' using strchr() function.
char *name="The Matrix(1999)"; char *ps; ps=strchr(name,'(');
Then add each character within brackets () to an char array
char y[5]=""; int p; for (p=1;p<strlen(ps+1);p++) { y[p-1]=ps[p]; } y[4]='\0';
Lastly convert resultant string to integer using atoi() function
year=atoi(y); printf("year=%d",year);
You can now apply required filters ti create array of strings of all movies prior to 2008
- Related Articles
- Convert a String to Integer Array in C/C++
- Convert an integer to a hex string in C++
- How to convert a string into integer in JavaScript?
- How to convert String to Integer and Integer to String in Java?
- How to convert a color integer to a hex String in Android?
- How to convert an integer to a hexadecimal string in Python?
- How to convert an integer to a octal string in Python?
- C# Program to Convert Integer to String
- C# program to convert binary string to Integer
- How to convert an integer to string with padding zero in C#?
- How to convert a string of any base to an integer in JavaScript?
- C# Program to convert integer array to string array
- How to convert a string vector into an integer vector in R?
- How to convert a list to string in C#?
- Convert Integer to Hex String in Java

Advertisements