简体   繁体   中英

How to check if command line arguments are lower case/ alphabetic and the sort?

I am really new to C programming (have previously done python and this is quite a difficult transition). I have been given a task to check the command line arguments and those which are not lower case alphabetic or numeric should be printed out with a given statement.

I have tried using a for loop and tried checking islower for argv[i] but that just crashes my program. The compiler gives this warning:

passing argument 1 of 'islower' makes integer from pointer without a cast

Can someone please give a general idea without actually typing out the code? Please do no type the code as I really want to do this myself (and also might get into trouble for plagiarism).

islower() checks the case of a single character, whereas argv is a char ** variable, meaning that argv[i] is a string (a char * ), not a character. Thus, to check whether a particular argument is lower-case, you need to iterate over the characters in it to check each one.

Which is also the meaning of the warning message you mention. Since the argument to islower() is an int (a single character), and you pass it a pointer (that is, argv[i] , which is a char * ), the compiler implicitly casts that pointer to the int that islower() requires, which is seldom intended behavior.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM