Chapter 11: The Stream Class and Arduino
Now it is time for us to move on to a new topic that we can explore in more detail as well.
In this chapter, we are going to work with the stream class, which is a bit different than what we have done before.
But if you are looking to work with strings in our coding, then we need to get a better idea of how the stream class is going to work for our needs.
You will find that the stream class is a fairly simple concept to work with, especially once we go through it a little bit more.
Despite its simplicity, though, we need to make sure that we realize how important it is to work with.
The stream class, when we work on it by itself, is going to be based on working through reading information from our chosen source, and then having this be the way that you design the sketch that you want to work with.
Since the stream is going to be all about reading the data, it is also important that we talk about using the keyboard and the mouse on this kind of class, even though these may not be related directly to the topic.
Hook up the keyboard and the mouse now because they will make the whole process a bit easier.
When you decide to work with this data, especially when you are getting all of the data prepared and ready to go, you will find that there are times when the character sets we want to work with are going to be a bit longer, such as enough characters to make a whole sentence.
The whole idea that comes with the string is that it will help us to handle this work on aboard.
Strings are going just to be sets of character values that are linked together in a manner that is similar to an array.
This means that they will be considered contiguous in the memory of our board, and when the computer takes a look at how this works, they will see them as one long and interconnected unit.
Working with the strings will simply mean that we need to take the time to learn how we can manipulate these units, as well as the abilities of the board, which will allow us to do this.
When we just look at the simplicity of the string, it is easy enough to understand.
Strings are just going to be what we know as character arrays.
This means that we are still going to find these strings to look like they are a part of the C language here, so if you have some experience with this language, you should notice how easy this is supposed to work.
Keep in mind that the strings here because of this are going to have some low-level abstraction that we need to work with.
For example, in many of the more modern languages or programming, the strings are not really going to be revealed in the character as one of these arrays.
Instead of working with these, they are going to be seen as an abstract object instead.
Even if they are seen as a character array in this, they will still be treated in this way.
A string is going to be easy to work with and is just composed of the n + 1 characters, where our n is going to be how many letters are found in that string in general.
So, if you are looking to make a string out o the word “hello” then we would know that we are working with six characters.
The reason that we have six characters instead of five is that the end is going to be a null terminating character, which will help the compiler know that the end of the array has been reached and that we are all done with this part of the code.
In addition to some of the work that we talked about above, it is possible to go through and define the string in a manner that is similar to how we are used to defining the array.
You can use this to make them bigger than the string that you plan to put into them as well.
When you go through this process of defining an array, you have to provide it with a value right off the bat, but it is also possible to start it off simple and just give it the size that you think should be there and then expand that out later on if it is not right or your needs.
This is one of the ways to make our strings more dynamic, while still allowing us to make some changes to what will happen to them later when we want to go through and do some of the rewritings that are necessary later on.
Now, as a programmer who is just getting started, all of this information is going to be important due to the fact that strings are fundamental and important to a lot of the different programs that you would like to use when handling information in your code.
This is especially true for those who would like to be able to handle the input and any of the output of a specific file that you are working on at the time.
Through this guidebook, we have been able to take some time to look through all of this and how it is going to work.
But now we need to take this a bit further and learn how we are able to go through this and define our strings.
The best coding that we can use to make this a reality is the following:
char myString[6] = “hello”;
You can then spend some time referring to this entire string at a later point with the name of the character.
Most of the data that is worked with by the board is going to be worked with in terms of how many bytes it is, and most of the actual textual data is going to be worked with in terms of C strings because it is easy to parse these characters when you would like.
One final thing to note here is that we are going to need some time to learn more about these parts and how they work.
And over time, we are going to be able to learn the exact right way to use these and to treat the strings so that they will do more of what we want along the way.
There are a lot of times when we need to work with the strings in our codes, and knowing how to use these, and how we can make these work for our own needs is going to be really important.
Take some time to look at how these strings work, along with some of the characters that come with them, to ensure that we are able to use them in the right manner as well.