I am implementing a shell in C11, and I want to check if the input has the correct syntax before doing a system call to execute the command. One of the possible inputs that I want to guard against is a string made up of only white-space characters. What is an efficient way to check if a string contains only white spaces, tabs or any other white-space characters?
The solution must be in C11, and preferably using standard libraries. The string read from the command line using readline()
from readline.h
, and it is a saved in a char array (char[]
). So far, the only solution that I've thought of is to loop over the array, and check each individual char
with isspace()
. Is there a more efficient way?