Strange print result

Hi, all,

I am a newbie on C++ and arduino, when I try to get the entry of integer from serial monitor, it runs into some problem. Some println are added into the codes to track the how the codes run.

boolean loopflag=false;
String brandName="";
byte Counts=0;
String buttonName="";

byte getNumber()
{
  char * value="";
  String s="";
  s=getChars();

  Serial.println("***DEBUG GETNUMBER s-->");
  Serial.println(s);

  ///***************************************
  for (int i=0; i< s.length(); i++)
  {
    value[i]=s[i];
    //value[i+1]='\0';

    Serial.println("value[i]");
    Serial.println(value);

  }
  ////****************************************
  
  Serial.println("***DEBUG GETNUMBER value-->");
  Serial.println(value);
  Serial.println("***END DEBUG***");
  Serial.println("");

  return atoi(value);

}

String getChars(void)
{
  char rcv=' ';
  String str;
  while (rcv!='\n')
  {
    if (rcv!=' ')
      str += rcv;
    if (Serial.available()>0)
      rcv=Serial.read();
    else
      rcv=' ';
  } 
  return str; 
}

void setup()
{
  Serial.begin(9600);
  Serial.print("Please enter the brand name of your remote:");

  brandName=getChars();
  Serial.println(brandName);

  Serial.println("Please enter how many records ");
  Serial.println("would be recorded per button:");
  Counts = getNumber();

  Serial.println("");
  Serial.println("Counts=");
  Serial.println(Counts,DEC);

  Serial.println(" ***END SETUP*** ");
}

void loop()
{
  if (!loopflag)
  {
    Serial.println("loop procedure");
    loopflag=true;
  }
}

The serial monitor would display like these:

Please enter the brand name of your remote:SONY
Please enter how many records
would be recorded per button:
*DEBUG GETNUMBER s–>
248
value
2loop procedure
value
24oop procedure
value
248op procedure
***DEBUG GETNUMBER value–>
248op procedure
END DEBUG
248op procedure
248op procedure
Counts=
248
END SETUP
48op procedure
_When I would like to display the value, it seems print out the its value and, strangely, the part of the string in loop() procedure. And the code calls ’ Serial.println("");’ once in line 32 in setup(), but there are two lines are printed out as ‘248op procedure’.

Would you please tell me what the errors I have made in the above codes.
BR,
Ardypro_

  char * value="";

This defines a pointer to read only memory.

    value[i]=s[i];

This tries to write there.

You need to statically size the array called value, like so:

char value[10];

PaulS: You need to statically size the array called value, like so:

char value[10];

I just changed the declaration as following:

char * value;
value = " ";

other parts remained unchanged, the result seemed correct. In this case, is value still read only?

char *value;// pointing to random location

value=" "; // now value is pointing to a string constant

//better you allocate a memory char value[10]; //value=" "; //you can't because array name is a constat pointer you can't point to other location value*=s[j];// OK location is already allocated to value so you can change its content;*