I feel like this is a really silly question, but I can’t seem to find an answer anywhere!
Is it possible to get a group of chars from a char array? to throw down some pseudo-code:
char arry[20] = "hello world!";
char part[10] = arry[0-4];
printf(part);
output:
hello
So, can I get a segment of chars from an array like this without looping and getting them char-by-char or converting to strings so I can use substr()?
In short, no. C-style “strings” simply don’t work that way. You will either have to use a manual loop, or
strncpy(), or do it via C++std::stringfunctionality. Given that you’re in C++, you may as well do everything with C++ strings!Side-note
As it happens, for your particular example application, you can achieve this simply via the functionality offered by
printf():