atoi
is for converting a string to integer. However, you want to convert a single character.
You can write:
number = token2[i] - '0';
This works because the digits '0'
through '9'
have consecutive character codes. There is no need to malloc or whatever.
Related Contents:
- How do I create an array of strings in C?
- Difference between char *str=”STRING” and char str[] = “STRING”?
- “error: assignment to expression with array type error” when I assign a struct field (C)
- C – Difference between “char var[]” and “char *var”?
- Return char[]/string from a function [duplicate]
- Varying string variable in an if condition
- Array type char[] is not assignable [duplicate]
- Literal string initializer for a character array
- How to find the ‘sizeof’ (a pointer pointing to an array)?
- What is the difference between char s[] and char *s?
- Is an array name a pointer?
- How do I concatenate const/literal strings in C?
- What is the difference between char array and char pointer in C?
- Difference between passing array and array pointer into function in C
- Using the equality operator == to compare two strings for equality in C [duplicate]
- Dynamic allocation of an unknown matrix in C
- What is the fastest substring search algorithm?
- What is the purpose of static keyword in array parameter of function like “char s[static 10]”?
- Are string literals const?
- Why does the indexing start with zero in ‘C’?
- Why is “a” != “a” in C?
- Getting “conflicting types for function” in C, why?
- How to pass a 2D array by pointer in C?
- initial value of int array in C
- typedef fixed length array
- Difference between array type and array allocated with malloc
- Why do we need to specify the column size when passing a 2D array as a parameter?
- Should I use char** argv or char* argv[]?
- Passing an array by reference in C?
- C programming, why does this large array declaration produce a segmentation fault?
- Segmentation Fault While Creating Large Arrays in C
- How does strcmp() work?
- Weird behavior when printing array in C?
- Append Char To String in C?
- Store data in array from input [duplicate]
- Dynamically create an array of strings with malloc
- How to split a string to 2 strings in C
- What’s a modern term for “array/pointer equivalence”?
- C char array initialization: what happens if there are less characters in the string literal than the array size?
- Are a, &a, *a, a[0], &a[0] and &a[0][0] identical pointers?
- why is array name a pointer to the first element of the array?
- How to convert a char array to a string?
- splitting a string into an array in C++ without using vector
- Resizing an array with C
- What is a “wide character string” in C language?
- How to get the string size in bytes?
- Equivalents to MSVC’s _countof in other compilers?
- Pick Random String From Array
- size of array in c
- Doesn’t a 2D array decay to pointer to pointer