user1143: I got a String which as I understand is an Arduino object, and got some C++ code:
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
#include <string.h>

LiquidCrystal_I2C lcd(0x20,16,2); 

boolean borrar = false;
String IP;

void setup()
{
  lcd.init();
  lcd.backlight();
  pinMode(13,OUTPUT);
  Serial.begin(9600);
  Serial1.begin(9600);

}

void loop() {

  while (Serial1.available()) { 

    char caracter = Serial1.read(); //Comprobamos el caracter 

    switch(caracter) {

    default:
                if (borrar) { 
                              IP = ""; 
                              lcd.clear();
                }

                lcd.print(caracter);
                delay(125);
                borrar = false;

                IP.concat(caracter);
                break;  

    case '\r':                
    case 0x0F:
    case 0x0A:  

                String res = "";
                borrar = true;
                int num= atoi(IP.c_str());
                if (num < 127) 
                  res="Clase A";
                if (num == 127) 
                  res="Direccion reservada";
                if (num > 127 && num < 192)
                  res="Clase B ";
                if (num >= 192 && num < 224)
                  res="Clase C ";
                if (num >= 224 && num < 240)
                  res="Clase D ";
                if (num >= 240 && num < 255)
                  res="Clase E ";
                break;  

  } //fin switch

}//serial disponible


}//fin programa

However, this won't compile because of this line:
int num= atoi(IP.c_str())

As IP is a String and such method works for string. How can I make it compatible (convert it)?

user42: Try updating to the latest version of the Arduino libraries/IDE.
The c_str() method was introduced to the Arduino String class quite recently, I believe. That line of code certainly works fine for me on Arduino IDE 1.0.5.

user84: Your code could be improved by removing the use of IP string altogether, and directly calculating its numeric value while characters come in through Serial1:
...
boolean borrar = false;
int IP = 0;
...

void loop() {
  while (Serial1.available()) { 
    char caracter = Serial1.read(); //Comprobamos el caracter 
    switch(caracter) {

    // NOTE it is better to replace default by the list of all digits...    
    case '0':
    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':
                if (borrar) { 
                              IP = 0; 
                              lcd.clear();
                }

                lcd.print(caracter);
                delay(125);
                borrar = false;

                IP *= 10;
                IP += (int) (caracter - '0');
                break;  

    case '\r':                
    case 0x0F:
    case 0x0A:  

                String res = "";
                borrar = true;
                int num= IP;
                if (num < 127) 
                  res="Clase A";
                if (num == 127) 
                  res="Direccion reservada";
                if (num > 127 && num < 192)
                  res="Clase B ";
                if (num >= 192 && num < 224)
                  res="Clase C ";
                if (num >= 224 && num < 240)
                  res="Clase D ";
                if (num >= 240 && num < 255)
                  res="Clase E ";
                break;  

  } //fin switch

}//serial disponible

}//fin programa

This way would bring you 2 advantages:

a bit faster than working with String
no dynamic memory allocation/deallocation (String does a lot of these) which might lead your program to heap fragmentation and eventually crash.

Note that I have not further refactored your code as I guessed it was just a snippet, not the complete code for your program. Otherwise, I would have performed further refinement like:

remove num variable since it is the same as IP now
replace res from String to const char* (to further reduce heap fragmentation due to String usage)


user1162: Try
unsigned char z[100];
IP.getBytes(z, 100);
z[IP.length()] = 0;
int n = atoi(z);

To retrieve bytes inside the string. This assumes IP string's length is shorter than 100. 

1143: <p>I got a <code>String</code> which as I understand is an Arduino object, and got some C++ code:</p>

<pre><code>#include &lt;Wire.h&gt; 
#include &lt;LiquidCrystal_I2C.h&gt;
#include &lt;string.h&gt;

LiquidCrystal_I2C lcd(0x20,16,2); 

boolean borrar = false;
String IP;

void setup()
{
  lcd.init();
  lcd.backlight();
  pinMode(13,OUTPUT);
  Serial.begin(9600);
  Serial1.begin(9600);

}

void loop() {

  while (Serial1.available()) { 

    char caracter = Serial1.read(); //Comprobamos el caracter 

    switch(caracter) {

    default:
                if (borrar) { 
                              IP = ""; 
                              lcd.clear();
                }

                lcd.print(caracter);
                delay(125);
                borrar = false;

                IP.concat(caracter);
                break;  

    case '\r':                
    case 0x0F:
    case 0x0A:  

                String res = "";
                borrar = true;
                int num= atoi(IP.c_str());
                if (num &lt; 127) 
                  res="Clase A";
                if (num == 127) 
                  res="Direccion reservada";
                if (num &gt; 127 &amp;&amp; num &lt; 192)
                  res="Clase B ";
                if (num &gt;= 192 &amp;&amp; num &lt; 224)
                  res="Clase C ";
                if (num &gt;= 224 &amp;&amp; num &lt; 240)
                  res="Clase D ";
                if (num &gt;= 240 &amp;&amp; num &lt; 255)
                  res="Clase E ";
                break;  

  } //fin switch

}//serial disponible


}//fin programa
</code></pre>

<p>However, this won't compile because of this line:</p>

<pre><code>int num= atoi(IP.c_str())
</code></pre>

<p>As IP is a <strong><code>String</code></strong> and such method works for <strong><code>string</code></strong>. How can I make it compatible (convert it)?</p>
 42: <p>Try updating to the latest version of the Arduino libraries/IDE.</p>

<p>The <code>c_str()</code> method was introduced to the Arduino String class quite recently, I believe. That line of code certainly works fine for me on Arduino IDE 1.0.5.</p>
 84: <p>Your code could be improved by removing the use of <code>IP</code> string altogether, and directly calculating its numeric value while characters come in through <code>Serial1</code>:</p>

<pre><code>...
boolean borrar = false;
int IP = 0;
...

void loop() {
  while (Serial1.available()) { 
    char caracter = Serial1.read(); //Comprobamos el caracter 
    switch(caracter) {

    // NOTE it is better to replace default by the list of all digits...    
    case '0':
    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':
                if (borrar) { 
                              IP = 0; 
                              lcd.clear();
                }

                lcd.print(caracter);
                delay(125);
                borrar = false;

                IP *= 10;
                IP += (int) (caracter - '0');
                break;  

    case '\r':                
    case 0x0F:
    case 0x0A:  

                String res = "";
                borrar = true;
                int num= IP;
                if (num &lt; 127) 
                  res="Clase A";
                if (num == 127) 
                  res="Direccion reservada";
                if (num &gt; 127 &amp;&amp; num &lt; 192)
                  res="Clase B ";
                if (num &gt;= 192 &amp;&amp; num &lt; 224)
                  res="Clase C ";
                if (num &gt;= 224 &amp;&amp; num &lt; 240)
                  res="Clase D ";
                if (num &gt;= 240 &amp;&amp; num &lt; 255)
                  res="Clase E ";
                break;  

  } //fin switch

}//serial disponible

}//fin programa
</code></pre>

<p>This way would bring you 2 advantages:</p>

<ol>
<li>a bit faster than working with <code>String</code></li>
<li>no dynamic memory allocation/deallocation (<code>String</code> does a lot of these) which might lead your program to <strong><a href="https://arduino.stackexchange.com/questions/763/im-using-too-much-ram-how-can-this-be-measured/787#787">heap fragmentation</a></strong> and eventually crash.</li>
</ol>

<p>Note that I have not further refactored your code as I guessed it was just a snippet, not the complete code for your program. Otherwise, I would have performed further refinement like:</p>

<ul>
<li>remove <code>num</code> variable since it is the same as <code>IP</code> now</li>
<li>replace <code>res</code> from <code>String</code> to <code>const char*</code> (to further reduce heap fragmentation due to <code>String</code> usage)</li>
</ul>
 1162: <p>Try</p>

<pre><code>unsigned char z[100];
IP.getBytes(z, 100);
z[IP.length()] = 0;
int n = atoi(z);
</code></pre>

<p>To retrieve bytes inside the string. This assumes IP string's length is shorter than 100. </p>
