Forget about ASCII code checks, use isdigit
or isnumber
(see man isnumber
). The first function checks whether the character is 0–9, the second one also accepts various other number characters depending on the current locale.
There may even be better functions to do the check – the important lesson is that this is a bit more complex than it looks, because the precise definition of a “number string” depends on the particular locale and the string encoding.
Related Posts:
- How does strtok() split the string into tokens in C?
- How to convert an int to string in C?
- What is a string of hexadecimal digits?
- How to convert an int to string in C?
- How to convert a string to integer in C?
- How do I create an array of strings in C?
- What is the difference between char s[] and char *s?
- How do I properly compare strings in C?
- How to convert an int to string in C?
- Returning string from C function
- How do I create an array of strings in C?
- Return char[]/string from a function [duplicate]
- How do I lowercase a string in C?
- Return char[]/string from a function
- How to clear all the elements of array in C?
- How do I concatenate const/literal strings in C?
- Reversing a string in C
- How to remove the character at a given index from a string in C?
- Split string with delimiters in C
- Allocating string with malloc
- Removing trailing newline character from fgets() input
- Does C have a string type?
- How to concatenate string and int in C?
- The difference between char * and char[] [duplicate]
- The difference between n++ and ++n at the end of a while loop? (ANSI C)
- Working on code to calculate cosine with factorial sum
- warning: implicit declaration of function
- What exactly is the difference between “pass by reference” in C and in C++?
- What does “collect2: error: ld returned 1 exit status” mean?
- Floating point exception (core dumped)
- what is the difference between uint16_t and unsigned short int incase of 64 bit processor?
- Correct format specifier for double in printf
- What is the behavior of integer division?
- Awesomium sdk download
- Bad File Descriptor with Linux Socket write() Bad File Descriptor C
- The importance of c enumeration (typedef enum) [duplicate]
- Error “initializer element is not constant” when trying to initialize variable with const
- Cannot assign requested address – possible causes?
- How do I properly compare strings in C?
- need help understanding the movzbl call in this function
- What is the difference between read and pread in unix?
- What does “control reaches end of non-void function” mean?
- connect Error: “No route to host”
- warning: implicit declaration of function
- C dynamically growing array
- Why do I get an assertion failure?
- Difference between int32, int, int32_t, int8 and int8_t
- C compile error: “Variable-sized object may not be initialized”
- What does WEXITSTATUS(status) return?
- Difference between a Structure and a Union
- Xcode – Warning: Implicit declaration of function is invalid in C99
- Error: control may reach end of non-void function in C
- The difference between stdout and STDOUT_FILENO
- C language: float % float why expression must have integral type
- Reading \r (carriage return) vs \n (newline) from console with getc?
- How to convert integer to string in C?
- Invalid pointer error on invoking free() after malloc in C
- In C, how should I read a text file and print all strings
- What does “Size in TCHARs” means?
- return makes integer from pointer without a cast [-Wint-conversion] return candidate
- Math constant PI value in C
- Cygwin – Makefile-error: recipe for target `main.o’ failed
- Why am I getting “undefined reference to sqrt” error even though I include math.h header?
- Why am I getting “undefined reference to sqrt” error even though I include math.h header?
- How can I use an array of function pointers?
- Expected declaration specifier error in function
- When and why to use malloc?
- Multiple definition of … linker error
- Does sizeof return the number of bytes or the number of octets of a type in C?
- C compile error: Id returned 1 exit status
- Efficient way to find task_struct by pid
- Why am I getting this memory access error ‘double free or corruption’?
- size of struct in C
- How can one print a size_t variable portably using the printf family?
- How to make sense of modulo in c
- Memory Clobbering Error
- “No such file or directory” error in CodeBlocks
- Check if input is integer type in C
- Uninitialized value was created by a heap allocation
- Makefile:1: *** missing separator. Stop
- double free or corruption (!prev) error in c program
- xorl %eax – Instruction set architecture in IA-32
- What does this GCC error “… relocation truncated to fit…” mean?
- ‘sprintf’: double precision in C
- C printing bits
- How do I find the time complexity (Big O) of while loop?
- Why do we use NULL in strtok()?
- Trim a string in C [duplicate]
- PTHREAD_MUTEX_INITIALIZER vs pthread_mutex_init ( &mutex, param)
- execvp: bad address error
- How detect malloc failure?
- A Simple, 2d cross-platform graphics library for c or c++?
- Removing last character in C
- Dereference void pointer
- Use of flag in c?
- Carriage return in C?
- Split string with multiple delimiters using strtok in C
- Difference between “while” loop and “do while” loop
- Swapping 2 Bytes of Integer
- GDB no such file or directory