decompose an int to String and show it

Hello everyone, thanks in advance with the help.
I can’t get to show me the individual characters of an int in serial monitor, for four characters.
If I assign 200 to the resistor variable, the result is effectively 200, but if I put 3300 it gives me anything. I am disoriented.

/*
   Decompose the digits of a resistor to give the color code
*/

unsigned int resistor=3300;
String RLetter="";
unsigned int digit;
char dig[4]={0,0,0,0};

void setup()
{
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  RLetras=(String)resistor;
  Serial.println(resistor);
  digitos=RLetras.length();
  Serial.println("your resistor has  " +String(digit)+" digit");
  for (int i=0;i<digit;i++){
    Serial.print(i);
    Serial.println(dig.charAt(i));
  }
}

void loop(){}

Your example is littered with typos and won’t compile.

Edit: Also please provide the output you are seeing. “Repeat the first 2, but not always“ really doesn’t adequately explain what you are seeing.

pcbbc:
Your example is littered with typos and won’t compile.

Edit: Also please provide the output you are seeing. “Repeat the first 2, but not always“ really doesn’t adequately explain what you are seeing.

Thanks a lot, now I modified it and I was a little more explicit.
I translate the variables into English and I was wrong. Corrected!
Now I am with the cell phone. Tomorrow I will give you output data. Thank you.

That still doesn't compile so any serial output you have will not have come from that code. Why are you not posting the real code?

Steve

Post the original code, don't try to convert it from a different language into English, having the variable names in a foreign language makes it a bit harder to understand, but not nearly as bad as the mess a translation program will make with the syntax of a programming language.

In the Arduinos with small amounts of SRAM, the String class can cause memory problems. See the evils of Strings. So it is better to get in the habit of using null terminated character arrays (c-strings or strings) instead.

An example that separates the digits of a resistance value into an array of characters and prints each character (digit). This works for any positive number 10 digits or less.

unsigned long resistor = 10000000;
char buffer[12];

void setup()
{
    Serial.begin(115200);
    ltoa(resistor, buffer, 10); 
    Serial.print("resistor  = ");
    Serial.println(resistor);
    byte resistanceLength = strlen(buffer);
    Serial.print("your resistance has ");
    Serial.print(resistanceLength);
    Serial.println(" characters");
    for(int n = 0; n < resistanceLength; n++)
    {
      Serial.print("digit ");
      Serial.print(n);
      Serial.print(" = ");
      Serial.println(buffer[n]);
    }
    Serial.println();
}

void loop()
{

}

Ok thk you. Sorry. I'm pretty newy.

groundFungus:
In the Arduinos with small amounts of SRAM, the String class can cause memory problems. See the evils of Strings. So it is better to get in the habit of using null terminated character arrays (c-strings or strings) instead.

An example that separates the digits of a resistance value into an array of characters and prints each character (digit). This works for any positive number 10 digits or less.

unsigned long resistor = 10000000;

char buffer[12];

void setup()
{
    Serial.begin(115200);
    ltoa(resistor, buffer, 10);
    Serial.print("resistor  = ");
    Serial.println(resistor);
    byte resistanceLength = strlen(buffer);
    Serial.print(“your resistance has “);
    Serial.print(resistanceLength);
    Serial.println(” characters”);
    for(int n = 0; n < resistanceLength; n++)
    {
      Serial.print("digit “);
      Serial.print(n);
      Serial.print(” = ");
      Serial.println(buffer[n]);
    }
    Serial.println();
}

void loop()
{

}

Thk u very much. It works. You are my new god!

Elegant and simple code adapted to my level. groundFungus you are a genius without a doubt.