I am getting input from terminal using "char *argv[]" parameter in main function. Now, I want to check whether all the inputs are not character (they are not necessarily int, they can be double) but I don't know how to do it here because inputs are pointers and it's not straightforward like when you get inputs from scanf() so just checking the ascii characters or something like that. Could someone help me with the issue?

Of course it's identical to the way you would validate input from scanf(). argv is just an array of strings. argv[0] is always (if the os supports this) the name of the executable program and each string after that is whatever you put on the command line. If you execute your program named "test.exe" like this:
c:\test one two three <Enter key>

Then

  • argv[0] = "test.exe" (sometimes it also has the full path)
  • argv[1]= "one"
  • argv[2] = "two"
  • argv[3] = "three"
  • argv[4] = NULL

argc is an integer that indicates the number of arguments in argv, and it's value is always greater or equal to 1. In the above example the value of argc will be 4.

But when I am trying something like:
argv[1] < 48 || argv[1] > 57
It gives me such a warning: comparison between pointer and integer and it does not produce a correct result.

argv[1] is a pointer to a string, if you want the first character in the string then it's argv[1][0]

this makes more sense anyway
argv[1][0] < '0' || argv[1][0] > '9'

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.