I'm working on a console in C and I want to make some commands. I simply take user input with getline()
, and then I have a string of characters. The problem is that I want to split the string into smaller "words", and the seperator would be the whitespace character (" ").
For example, the string of characters "Hello World!" would be split into {"Hello", "World!"}, so I want to ignore invisible characters like whitespaces, \n, \t and other invisible characters.
Basically, I want something like the string.split()
function in Python. The function would return a array with all the strings ({{'H', 'e', 'l', 'l', 'o', '\0'}, {'W', 'o', 'r', 'l', 'd', '!', '\0'}}) .
I'm fairly new to C, but I do have some experience in C++.
I tried finding some builtin functions, but considering it is C, not C++, I could not find anything appropriate for my problem. I still do not really understand how do arrays work in C.