Now how do I know whether Query string contains only integers or contains both characters and integers. If it contains only integers I want to take some action or else different action.
Depending on your exact requirements (which are slightly unclear), strtol() might not do what you need.
You start by saying:
>>How do I check if a string is an integer
and then later say:
>>how do I know whether Query string contains only integers
These are two different requirements.
To achieve the former, you would use strtol() as shown in the last link supplied by Dian.
To achieve the latter, strtol() will not necessarily work, as the data could be any number of bytes in length, and the content may well exceed the value an integer (int) can store (INT_MAX or UINT_MAX, limits.h). Therefore, the validation method would be to walk through the array checking each byte using isdigit() (ctype.h) to determine if it is a numeric. Using this method, you can test any number of bytes.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.