user20714: I created a simple library for formatting text output on the serial monitor. It has thee functions, one that creates carriage returns, one that sets the number of spaces between characters and the last one prints dashes. I followed the tutorial on the Arduino.cc site. The problem I have is that I can’t pass the value to each of the functions when I call them in the code. If you look at the screenshot from the sketch when I create an instance of nFormat it requires me to put a value in and it passes that value to each of the functions (lines, spaces, dashes). I want to be able to specify the value directly when I call the function. See the second red line on the output screenshot. I know this post is a bit long I would appreciate it if someone could point me in the right direction. 
nFormat.h
#ifndef nFormat_h 
#define nFormat_h

#include "Arduino.h"

class nFormat
{
  public:
    nFormat(int counter);

    void lines();
    void spaces();
    void dashes();

   private:
    int _counter;
};

#endif

nFormat.cpp
#include "Arduino.h"
#include "nFormat.h"

nFormat::nFormat(int counter)
{
    _counter=counter;
}

void nFormat::lines()
{   
for (int x = 0; x < _counter; x++)
    {
        Serial.println(" ");
    }

}

void nFormat::spaces()
{
    for (int x = 0; x < _counter; x++)
    {
        Serial.print(" ");
    }
}

void nFormat::dashes()
{
    for (int x = 0; x < _counter; x++)
    {
        Serial.print("-");
    }



user7508: If you want to specify the number of spaces/dashes/... every time you
call any of these methods, you just have to make that number a parameter
of the method:
void lines(int count)
{
    for (int x = 0; x < count; x++)
        Serial.println();
}

Then, your class does not need its private _counter. Then, since there
is no data in the class, you do not need to instantiate it: just make
all the methods static and call the methods as
nFormat::method_name(). And since you are not making instances, you do
not need a constructor either. And since the methods are really trivial,
there is no point in implementing them in a .cpp file: you can just
inline them in the class declaration. Combining all this gives this small
demo program:
class nFormat
{
  public:
    static void lines(int count)
    {
        for (int x = 0; x < count; x++)
            Serial.println();
    }

    static void spaces(int count)
    {
        for (int x = 0; x < count; x++)
            Serial.print(" ");
    }

    static void dashes(int count)
    {
        for (int x = 0; x < count; x++)
            Serial.print("-");
    }
};

void setup()
{
    Serial.begin(9600);
    nFormat::dashes(5);
    nFormat::lines(5);
    nFormat::spaces(5);
    nFormat::dashes(5);
}

void loop() {}

It could be noted than this class serves only to avoid putting all the
functions in the global namespace. It is essentially a namespace. You
could as well replace class by namespace (and remove the public
keyword) to make that more explicit.

20714: <p>I created a simple library for formatting text output on the serial monitor. It has thee functions, one that creates carriage returns, one that sets the number of spaces between characters and the last one prints dashes. I followed the tutorial on the Arduino.cc site. The problem I have is that I can’t pass the value to each of the functions when I call them in the code. If you look at the screenshot from the sketch when I create an instance of nFormat it requires me to put a value in and it passes that value to each of the functions (lines, spaces, dashes). I want to be able to specify the value directly when I call the function. See the second red line on the output screenshot. I know this post is a bit long I would appreciate it if someone could point me in the right direction. </p>

<p>nFormat.h</p>

<pre><code>#ifndef nFormat_h 
#define nFormat_h

#include "Arduino.h"

class nFormat
{
  public:
    nFormat(int counter);

    void lines();
    void spaces();
    void dashes();

   private:
    int _counter;
};

#endif
</code></pre>

<p>nFormat.cpp</p>

<pre><code>#include "Arduino.h"
#include "nFormat.h"

nFormat::nFormat(int counter)
{
    _counter=counter;
}

void nFormat::lines()
{   
for (int x = 0; x &lt; _counter; x++)
    {
        Serial.println(" ");
    }

}

void nFormat::spaces()
{
    for (int x = 0; x &lt; _counter; x++)
    {
        Serial.print(" ");
    }
}

void nFormat::dashes()
{
    for (int x = 0; x &lt; _counter; x++)
    {
        Serial.print("-");
    }
</code></pre>

<p><a href="https://i.stack.imgur.com/zWlca.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zWlca.jpg" alt="output"></a></p>
 7508: <p>If you want to specify the number of spaces/dashes/... every time you
call any of these methods, you just have to make that number a parameter
of the method:</p>



<pre class="lang-c++ prettyprint-override"><code>void lines(int count)
{
    for (int x = 0; x &lt; count; x++)
        Serial.println();
}
</code></pre>

<p>Then, your class does not need its private <code>_counter</code>. Then, since there
is no data in the class, you do not need to instantiate it: just make
all the methods <code>static</code> and call the methods as
<code>nFormat::method_name()</code>. And since you are not making instances, you do
not need a constructor either. And since the methods are really trivial,
there is no point in implementing them in a .cpp file: you can just
inline them in the class declaration. Combining all this gives this small
demo program:</p>

<pre class="lang-c++ prettyprint-override"><code>class nFormat
{
  public:
    static void lines(int count)
    {
        for (int x = 0; x &lt; count; x++)
            Serial.println();
    }

    static void spaces(int count)
    {
        for (int x = 0; x &lt; count; x++)
            Serial.print(" ");
    }

    static void dashes(int count)
    {
        for (int x = 0; x &lt; count; x++)
            Serial.print("-");
    }
};

void setup()
{
    Serial.begin(9600);
    nFormat::dashes(5);
    nFormat::lines(5);
    nFormat::spaces(5);
    nFormat::dashes(5);
}

void loop() {}
</code></pre>

<p>It could be noted than this class serves only to avoid putting all the
functions in the global namespace. It is essentially a namespace. You
could as well replace <code>class</code> by <code>namespace</code> (and remove the <code>public</code>
keyword) to make that more explicit.</p>
